我尝试在插件woocommerce wordpress中定制统一费率,违约统一费率任何类45美元,但我想要的产品有11美元的价格将免费送货 . 请帮我!
add_filter('woocommerce_shipping_free_shipping_is_available', 'diy_free_delivery');
function diy_free_delivery($rates, $package){
$product = new WC_Product();
$price = $product->regular_price;
if($price > 11){
unset( $rates['flat_rate'] );
$free_shipping = $rates['free_shipping'];
$rates = array();
$rates['free_shipping'] = $free_shipping;
}
return $rates;
}
1 回答
您应该使用woocommerce_package_rates过滤器来确定哪些出货选项可用,具体取决于购物车的 Value . 过滤器将传入
$available_methods
,您可以使用WC()->get_cart_subtotal()根据购物车的 Value 在功能中修改 .