我尝试在插件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;
}
答案 0 :(得分:0)
您应该使用woocommerce_package_rates
过滤器来确定哪些送货方式可用,具体取决于购物车的价值。过滤器将使用WC()->get_cart_subtotal()
根据购物车的价值传递您可以在功能中修改的$available_methods
。
add_filter( 'woocommerce_package_rates', 'diy_free_delivery' );
function diy_free_delivery( $available_methods ){
// check to see if the cart total is more than $11
if ( WC()->get_cart_subtotal() > 11 ){
// if it is we *only* want to show the free shipping
return array( 'free_shipping' => $available_methods['free_shipping'] );
} else {
// if not we want to remove free_shipping and return the other methods
unset( $available_methods['free_shipping'] );
return $available_methods;
}
}