Я хочу показать вариант бесплатной доставки (не стандартная бесплатная доставка woocommerce), предоставляемый плагином, который подключается к API службы доставки, когда количество товаров в корзине превышает 24.
I нашел приведенный ниже код в Интернете, который в основном делает то, что мне нужно, единственная проблема в том, что мне нужно указать параметры доставки на ярлыке метода доставки, а не фактический тип способа доставки, как показано ниже, то есть «free_shipping».
add_filter('woocommerce_package_rates', 'show_hide_free_shipping', 10, 2);
function show_hide_free_shipping($available_shipping_methods, $package){
$minimum_number_of_item = 24; //Give here minumum number of items to allow freeshipping
$free_shipping = false;
global $woocommerce;
$item_count = 0;
foreach (WC()->cart->cart_contents as $key => $item) {
$item_count += $item['quantity'];
}
if( $item_count >= $minimum_number_of_item ){
$free_shipping = true;
}
if($free_shipping){
foreach($available_shipping_methods as $shipping_method => $method){
if( strpos( $shipping_method, 'free_shipping' ) === false ) {
unset($available_shipping_methods[$shipping_method]);
}
}
}
else{
foreach($available_shipping_methods as $shipping_method => $method){
if( strpos( $shipping_method, 'free_shipping' ) !== false ) {
unset($available_shipping_methods[$shipping_method]);
}
}
}
return $available_shipping_methods;
}
Я далеко не волшебник php / wordpress, поэтому я был бы очень признателен за любую помощь, которую мог получить.