【问题标题】:Add custom fee to recurring total WooCommerce subscription [duplicate]将自定义费用添加到 WooCommerce 总订阅中 [重复]
【发布时间】:2018-09-15 01:11:25
【问题描述】:
function add_woocommerce_stripe_fee() {
    if ( ( is_admin() && ! defined( 'DOING_AJAX' ) ) || ! is_checkout() )
        return;

    $chosen_gateway = WC()->session->chosen_payment_method;

    if ( 'stripe'  ==  $chosen_gateway ) {
        $fee = (WC()->cart->cart_contents_total * .035) +0.35;       
        WC()->cart->add_fee( 'Stripe Fee', $fee, false, '' );
    }
}
add_action( 'woocommerce_cart_calculate_fees','add_woocommerce_stripe_fee' );

它不会添加到经常性购物车总数,但适用于普通产品(不适用于订阅产品)。任何帮助将不胜感激。这可能吗?

【问题讨论】:

  • 先问这个问题-我认为应该关闭另一个问题:)

标签: php woocommerce hook-woocommerce woocommerce-subscriptions


【解决方案1】:

我在similar question 上提供了更深入的答案。

长话短说尝试添加这个:

add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );

并查看Woocommerce doc,它提供了一些可能对您有所帮助的示例。

【讨论】:

  • 这个钩子是在哪个版本引入的?
猜你喜欢
  • 2017-01-29
  • 2019-06-30
  • 1970-01-01
  • 1970-01-01
  • 2021-07-01
  • 2021-05-07
  • 2016-02-23
  • 2016-07-26
  • 2021-02-18
相关资源
最近更新 更多