WooCommerce check if free shipping is activated

倖福魔咒の 提交于 2021-02-10 19:49:36

问题


I want to show if free shipping is activated on my WooCommerce cart, to tell people "Hey, you've got free shipping!". Free shipping can be activated by either order amount or a coupon.

I have tried this code, but it returns an empty array.

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

Otherwise I could have checked if free_shipping was set.

Hope you all have some great ideas how to get this working :)


回答1:


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() . "+";
}


来源:https://stackoverflow.com/questions/26194911/woocommerce-check-if-free-shipping-is-activated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!