Get Shipping Zone Method
-
I’m trying to display the customers shipping zone’s name, ID and method e.g. Flat Rate.
Then do an IF statement on those answers, I can do everything except for “get the method ID” as it always errors;
Uncaught Error: Call to undefined method WC_Shipping_Zone::get_method_id()
I’ve checked and it seems to be correct method term so not sure why nothing is returning…
function woo_wc_minimum_order_amount() { $minimum = 20; // change this to your minimum order amount // Get cart shipping packages $shipping_packages = WC()->cart->get_shipping_packages(); // Get the WC_Shipping_Zones instance object for the first package $shipping_zone = wc_get_shipping_zone( reset( $shipping_packages ) ); $zone_id = $shipping_zone->get_id(); // Get the zone ID $zone_name = $shipping_zone->get_zone_name(); // Get the zone name $zone_method = $shipping_zone->get_method_id(); // The shipping method slug // Testing output echo '<p>Zone id: ' . $zone_id . ' | Zone name: ' . $zone_name . ' | Zone name: ' . $zone_method . '</p>'; if ( WC()->cart->subtotal < $minimum ) { if ( is_cart() ) { wc_print_notice( sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error' ); remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 ); } else { wc_add_notice( sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error' ); remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 ); } } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get Shipping Zone Method’ is closed to new replies.