Ich möchte eine Reihe von Versandmethoden ausblenden, wenn eine Reihe von Produkten auf WooCommerce ausgewählt ist
Ich glaube, ich bin fast am Ziel, aber ich erhalte eine Fehlermeldung unset( $rates[$method_ids] )
Linie.
Hier ist, was ich bisher habe:
add_filter( 'woocommerce_package_rates', 'specific_products_shipping_methods_hide_many', 10, 2 );
function specific_products_shipping_methods_hide_many( $rates, $package ) {
$product_ids = array( 240555 ); // HERE set the product IDs in the array
$method_ids = array( 'flat_rate:7', 'flat_rate:13', 'flat_rate:26', 'flat_rate:27', 'local_pickup:24' ) ; // HERE set the shipping method IDs
$found = false;
// Loop through cart items Checking for defined product IDs
foreach( $package['contents'] as $cart_item ) {
if ( in_array( $cart_item['product_id'], $product_ids ) ){
$found = true;
break;
}
}
if ( $found )
unset( $rates[$method_ids] );
return $rates;
}
Irgendein Rat?