【问题标题】:Unhook remove_non_recurring_fees() WooCommerce Subscriptions functionUnhook remove_non_recurring_fees() WooCommerce 订阅功能
【发布时间】:2021-02-01 21:23:08
【问题描述】:

在购物车计算总数时,我正拼命尝试删除一个动作。

这是我的代码:

remove_action('woocommerce_cart_calculate_fees', array('WCS_Cart_Renewal', 'remove_non_recurring_fees'), 1000);

在 WooCommerce 订阅插件上进行原始操作时:

// Remove non-recurring fees from renewal carts. Hooked in late (priority 1000), to ensure we handle all fees added by third-parties.
        add_action( 'woocommerce_cart_calculate_fees', array( $this, 'remove_non_recurring_fees' ), 1000 );

很遗憾,我无法删除 remove_non_recurring_fees 挂钩函数。

知道为什么吗?

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce woocommerce-subscriptions


    【解决方案1】:

    当您查看WCS_Cart_Renewal Class and remove_non_recurring_fees() function 时,您会看到此功能在涉及订阅时首先删除所有费用并仅重新添加经常性费用。这个函数被挂钩的优先级为 1000。

    除了尝试删除触发此功能的动作挂钩之外,您还有 2 个其他选择:

    1)。对于您通过主题的 functions.php 文件添加的自定义费用:

    您只需使用更高的优先级,如下例所示:

    add_action( 'woocommerce_cart_calculate_fees', 'my_custom_fee', 2000 );
    function my_custom_fee( $cart ) {
         // Your code
    }
    

    2)。或者更好地使用woocommerce_subscriptions_is_recurring_fee 可用的过滤器钩子:

    这个过滤器钩子允许重新添加所有需要的费用,这些费用不会通过这个简单的代码行重复:

    add_filter( 'woocommerce_subscriptions_is_recurring_fee', '__return_true' );
    

    代码进入活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-01
      • 2019-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 2020-08-17
      • 2018-09-02
      相关资源
      最近更新 更多