Woocommerce coupoun management



有人知道我怎么能做这样的coupoun吗?

我想做基于%的折扣coupoun。

  1. 您可以将coupoun添加到非销售产品中,但它应该使用该产品的全价并从中计算,而不是说它会得到双倍折扣(非销售产品+基于%的折扣(使用coupoun((

有什么想法,怎么做?

是的,可以将此代码添加到functions.php文件中。在下面的代码"中;五十";是所使用优惠券的名称。在woo commerce中创建基于%的优惠券。

add_filter('woocommerce_coupon_get_discount_amount', 'woocommerce_discount_from_the_original_price', 10, 5 );
function woocommerce_discount_from_the_original_price( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
if ($coupon->discount_type == 'percent' && $coupon->code == 'fifty') {
$discount_percentage = $coupon->amount / 100;
$item                = wc_get_product($cart_item['product_id']);
if ($item) {
if ( $item->is_type( 'simple' ) ) {
$sale_price    = $item->sale_price;
$regular_price = $item->regular_price;
if ( ($sale_price && $regular_price) && ($sale_price !==  $regular_price) ) {
$discount_from_regular_price = $regular_price * $discount_percentage; 
$discount = $discounting_amount - ($discount_from_regular_price * $cart_item['quantity']); 
}
} elseif ( $item->is_type( 'variable' ) ) {
$variable_product = new WC_Product_Variation( $cart_item["variation_id"] );
$sale_price    = $variable_product->sale_price;
$regular_price = $variable_product->regular_price;

if ( ($sale_price && $regular_price) && ($sale_price !==  $regular_price) ) {
$discount_from_regular_price = $regular_price * $discount_percentage;
$discount = $discounting_amount - ($discount_from_regular_price * $cart_item['quantity']);
}
}
}
}
return $discount;
}

相关内容

  • 没有找到相关文章

最新更新