亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Woocommerce 優惠券管理

Woocommerce 優惠券管理

躍然一笑 2023-09-21 14:22:36
有誰知道我怎樣才能制作這樣的優惠券或者以前做過嗎?我想制作基于百分比的折扣優惠券。您可以將優惠券添加到打折產品中,但它應該使用該產品的全價并從那里計算,而不是像雙重折扣(打折產品 + 基于百分比的折扣(帶優惠券))有什么想法,怎么辦?
查看完整描述

1 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

是的,可以將此代碼添加到您的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;

}


查看完整回答
反對 回復 2023-09-21
  • 1 回答
  • 0 關注
  • 82 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號