2014-10-04 73 views
0

我想告訴人們,如果我的WooCommerce購物車上已激活免費送貨,請告訴人們「嘿,你有免費送貨!」。免費送貨可以通過訂單金額或優惠券激活。WooCommerce檢查是否已激活免費送貨

我試過這段代碼,但它返回一個空數組。

global $woocommerce; 
$woocommerce->shipping->get_shipping_methods(); 

否則我可以檢查是否設置了free_shipping。

希望你們有一些偉大的想法如何得到這個工作:)

回答

0
global $woocommerce; 
$shipping_methods = $woocommerce->shipping->load_shipping_methods(); 
if($shipping_methods['free_shipping']->enabled == "yes") 
{ 
    $cart_total_amount = floatval(preg_replace('#[^\d.]#', '', $woocommerce->cart->get_cart_total())); 

    if($shipping_methods['free_shipping']->min_amount <= $cart_total_amount) echo "Hey, you've got free shipping!"; 
    else echo "Free shipping on all orders of " . $shipping_methods['free_shipping']->min_amount . get_woocommerce_currency_symbol() . "+"; 
} 
相關問題