购物车中商品倍数的按商品_id的WooCommerce折扣

时间:2020-08-01 20:51:03

标签: php wordpress woocommerce cart discount

我有一款产品售价为£69.92。对同一产品的每4件商品应用14.2%的折扣。数学上:

  • 获取购物车中特定产品(按ID)的产品数量作为股息
  • 将股息除以除数(在这种情况下,除数为4)
  • 将除数的商乘以240,将余数乘以69.95,然后将它们相加:

结果=(商* 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。 无法为我工作。

0 个答案:

没有答案