我有一款产品售价为£69.92。对同一产品的每4件商品应用14.2%的折扣。数学上:
结果=(商* 69.95(100-14.2))/ 100 +(余数* 69.95)。
假设购物车中特定产品的数量为7。我编写的逻辑没有这样的WooCommerce功能:
<?php
$dividend = 7; //get product quantity by id from cart
$divisor = 4;
$quotient = intdiv($dividend, $divisor);
$remainder = $dividend % $divisor;
$price = 69.95; // use sale or actual price if sale is not set.
$price = ($quotient *$price(100 - 14.2))/100 + ($remainder * $price)
?>
购买4件商品=£240。促销价=£69.95。购买7件=(240)+(3 * 69.95)= 449.85
理想情况下,我希望能够对WordPress Admin区域中具有不同折扣的不同产品执行此操作。这将允许其他用户无需任何代码即可应用折扣。
我使用以下代码: Cart bulk quantity discount for specific products in Woocommerce。 无法为我工作。