【发布时间】:2018-11-04 13:02:07
【问题描述】:
我需要在 AJAX 响应函数中执行/调用woocommerce_cart_calculate_fees 操作,如下所示,
要求是在购物车中添加特定条件下的折扣。
add_action( 'wp_ajax_tcf_et_add_estimate_to_cart', 'my_function' );
my_function()
{
// ADD SOME PRODUCTS TO THE CART
if( certain condition )
{
add_action( 'woocommerce_cart_calculate_fees', 'add_discount', 1, 1 );
function add_discount( $cart )
{
global $woocommerce;
$cart->add_fee( 'Discount' , -100 );
return $cart;
}
}
// some code
}
我知道这是完全错误的,但正在寻找一种以 wordpress 方式执行此操作的方法?比如在my_function 之外写woocommerce_cart_calculate_fees 并在需要时调用它。
是否有任何技巧或技术可以执行此操作,否则在 Wordpress 中无法执行?
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce