由于物流原因(多个仓库),我使用下面的代码片段来限制每个订单只能购买一个唯一的WooCommerce产品.我使用一个属性来指定仓库,如果仓库/属性相同,则允许客户订购多个产品会很方便.有人能帮我修改一下代码片段吗?
add_filter( 'woocommerce_add_to_cart_validation', 'wc_limit_one_per_order', 10, 2 );
function wc_limit_one_per_order( $passed_validation, $product_id ) {
if ( WC()->cart->get_cart_contents_count() >= 1 ) {
wc_add_notice( __( 'This product cannot be purchased with other products. Please, empty your cart first and then add it again.', 'woocommerce' ), 'error' );
return false;
}
return $passed_validation;
}
我想增加这样的东西,但我不知道该怎么做.
$attribute = $product->get_attribute('pa_warehouse');
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
$product = $values['data'];