0
お客様が商品5を追加する場合は、商品数量に基づいて販売を強制したい1アクセサリーを追加する必要があります。それらが5を超える場合は、2つのアクセサリを追加する必要があります。 アクセサリは5の倍数で追加する必要があります。wooocommerceの商品数量に基づいて販売された売り上げ額
お客様が商品5を追加する場合は、商品数量に基づいて販売を強制したい1アクセサリーを追加する必要があります。それらが5を超える場合は、2つのアクセサリを追加する必要があります。 アクセサリは5の倍数で追加する必要があります。wooocommerceの商品数量に基づいて販売された売り上げ額
この試し:コードカート量回添加物の量と一致する量でカートに$additional_product_id
を追加する必要があり
add_action('woocommerce_add_to_cart', 'prefix_add_additional_product', 10, 6);
/**
* Adds additional product to cart based on the quantity of an added product
*/
function prefix_add_additional_product($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
// Get the cart
$cart = WC()->cart->get_cart();
// Nothing, if the cart is empty
if (0 == count($cart)) {
return;
}
// Enter the free product ID
$additional_product_id = 96;
// Don't add accessory when adding the same accessory
$added_product_id = 0 < $variation_id ? $variation_id : $product_id;
if ($added_product_id == $additional_product_id) {
return;
}
// You can add checks for specific product ID or some other requirements here
$additional_product_quantity = (int) ($quantity/5);
WC()->cart->add_to_cart($additional_product_id, $additional_product_quantity);
}
https://gist.github.com/vanbo/f42cfa8bdf593013f77dda605a9876bb
は5 によって分けすることができますコードをカートに追加するフックに引っ掛けます。