2014-02-26 117 views
1

我已經試圖在購買我的自定義Woocommerce插件之前申請購物車優惠。但它並沒有通過我自定義插件文件中的動作鉤woocommerce_cart_discounts_before_tax得到應用。如何在woocommerce申請購物車優惠稅前

以下是我的自定義插件文件中的代碼。

public function custom_discount(){ 
       global $woocommerce; 
       $abc = woocommerce_price(5); 
       echo $abc; 
} 

和行動掛鉤

if(!empty($_POST['apply_discount_woo'])){ 
        add_action('woocommerce_cart_discounts_before_tax', array(&$this,'custom_discount')); 
       } 

我碰到下面的屏幕

enter image description here

的屏幕截圖顯示5 $小計以上,但不應用到購物車中,並顯示錯誤的總數。

+0

從'wp-admin' - >'編輯優惠券',有一個複選框可以指定在稅前或稅後使用優惠券。 –

+0

@AkshayPaghdar我沒有申請優惠券折扣。我想申請一個自定義折扣,說5美元的clickof應用折扣,你會看到截圖。 –

+0

你有沒有工作過? –

回答

0

我認爲你需要返回值,而不是echo:

public function custom_discount(){ 
    global $woocommerce; 
    $abc = woocommerce_price(5); 
    return $abc; 
} 

不過,我認爲這也將覆蓋已應用於其他折扣。

相關問題