【问题标题】:Woocommerce subscription custom fee add to recurring totalWoocommerce 订阅自定义费用添加到经常性总额中
【发布时间】:2017-01-29 03:19:35
【问题描述】:

我想问一下如何将自定义费用添加到 woocommerce 订阅经常性总数中?

在网上找到这个:

function woo_add_cart_fee() {
  global $woocommerce;
  $woocommerce->cart->add_fee( __('Custom', 'woocommerce'), 5 );
}

add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );

但是,某些功能仅适用于常规产品。 NOT SUBSCRIPTION - 它不会将费用添加到经常性总计中。

【问题讨论】:

    标签: php wordpress woocommerce subscription


    【解决方案1】:

    截至目前,WooCommerce 订阅不支持在经常性总计中增加费用。

    【讨论】:

      【解决方案2】:

      这可能对您没有任何用处,但您可能会发现这很有用:https://docs.woocommerce.com/document/subscriptions/develop/recurring-cart-fees/

      我相信这个例子与你的问题有关:

      在某些情况下,您可能会要求仅将费用应用于正在进行的 任何订阅的定期付款。为此,您需要...添加一个条件来检查是否 传递给回调的购物车是循环购物车,或者 标准 WooCommerce 购物车。

      循环购物车有一个$recurring_cart_key 属性,我们可以使用它来 确定购物车是否是经常性购物车。

      add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );
      
      function add_recurring_postage_fees( $cart ) {
         // Check to see if the recurring_cart_key is set 
         if ( ! empty( $cart->recurring_cart_key ) ) {
             $cart->add_fee( 'Postage', 5 );
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2019-06-30
        • 2018-09-15
        • 2018-06-03
        • 2016-10-02
        • 1970-01-01
        • 2017-02-01
        • 2021-07-01
        • 2019-01-01
        • 1970-01-01
        相关资源
        最近更新 更多