add_action('woocommerce_calculate_totals', 'modify_shipping_totals');
function modify_shipping_totals($cart) {
if($cart->get_cart_contents_count() < 6) {
$cart->shipping_total = ( 15/100 ) * $this->cart_contents_total;
// shipping cost will be 15% of cart content total
// you may also want to modify the shipping tax.
$cart->shipping_tax_total = 0;
} else {
$cart->shipping_total = 6.99;
$cart->shipping_tax_total = 0;
}
}
3条答案
按热度按时间abithluo1#
您需要将一个函数与
woocommerce_calculate_totals
操作挂钩,该操作在计算最终购物车总额之前触发。woocommerce_calculate_totals
操作提供WC_Cart
示例,您可以根据需要在该示例上执行操作。有关可更改变量的更多参考,请参阅WC_Cart文档。
gev0vcfq2#
kupeojn63#
Pranav解决方案可以在init钩子内调用add_action,如下所示: