Я пытаюсь написать функцию, которая предложит бесплатную доставку (удалите все другие варианты), если заказ превышает 5 фунтов (80 унций), но он не работает, хотя код кажется правильным.WooCommerce Бесплатная доставка, если более 5 фунтов
Это то, что у меня есть:
// Hide ALL shipping options but FREe when over 80 ounches (5 pounds)
add_filter('woocommerce_available_shipping_methods', 'ship_free_if_over_five_pounds' , 10, 1);
/**
* Hide ALL Shipping option but free if over 5 pounds
*
* @param array $available_methods
*/
function ship_free_if_over_five_pounds($available_methods) {
global $woocommerce;
$whats_the_weight = $woocommerce->cart->cart_contents_weight;
if($whats_the_weight != 80) :
// Get Free Shipping array into a new array
$freeshipping = array();
$freeshipping = $available_methods['free_shipping'];
// Empty the $available_methods array
unset($available_methods);
// Add Free Shipping back into $avaialble_methods
$available_methods = array();
$available_methods[] = $freeshipping;
endif;
return $available_methods;
}
Есть мысли?
код основан на примере # 19 на этом сайте:
My 25 Best WooCommerce Snippets For WordPress Part 2