使用 https://docs.python.org/3/library/asyncio-task.html 的代码可以正常工作,但是当输入 2 个以上的 ID 时它不起作用。它仅适用于单个 ID。
试试这个:
add_filter( 'woocommerce_add_to_cart_validation', 'chequear_bundle_product', 10, 3 );
function chequear_bundle_product( $passed, $product_id, $quantity ) {
$ingredientesID = array(37, 67); // Products ID do not want them to be added if the cart is empty.
if( WC()->cart->is_empty() && array_intersect($ingredientesID) == $product_id) {
wc_add_notice( __("Este ingrediente no se puede comprar solo."), 'notice' );
return false;
}
return $passed;
}
我怎样才能让它与多个 ID 一起工作,我感谢所有有用的帮助。
编辑 我能够解决以下问题。我感谢给我这个想法的用户。
///$ingredientesID = array(37, 67);
$cart_is_empty = WC()->cart->is_empty();
if ($cart_is_empty && 37 == $product_id){
wc_add_notice( __("Este ingrediente no se puede comprar solo."), 'notice' );
return false;
}elseif ($cart_is_empty && 67 == $product_id){
wc_add_notice( __("Este ingrediente no se puede comprar solo."), 'notice' );
return false;
}