1
votes

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

1 Answers

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