Save Free Shipping Minimum Order Amount to Order
-
I’m trying to save the minimum order amount for free shipping to order data regardless of the shipping method chosen.
- The minimum order amount for free shipping is different in every shipping zone segregated through post codes.
- The user is unable to select the shipping method.
- The flat rate is chosen by default if the minimum order amount for free shipping is not achieved.
- If the minimum order amount is achieved, free shipping shall be the only option available and is chosen.
I intend to pull the minimum order amount for free shipping of the shipping zone where the user is based in via the billing details inserted in checkout.
I’ve found a similar working code but this only works if the shipping method chosen is free shipping, which does not work in my favor if the minimum order amount is not achieved.
add_action( 'woocommerce_checkout_create_order', 'wpo_safe_free_shipping_amount_within_order_data' ); function wpo_safe_free_shipping_amount_within_order_data( $order ) { $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); // If a free shipping method is selected... if ( strpos( $chosen_shipping_methods[0], 'free_shipping' ) !== false ) { list( $shipping_name, $shipping_id ) = explode( ':', $chosen_shipping_methods[0] ); // ...get the minimum amount from its settings $free_shipping_settings = get_option( "woocommerce_{$shipping_name}_{$shipping_id}_settings" ); $min_amount = $free_shipping_settings['min_amount']; // If there is a minimum amount set, save it within the order data if ( ! empty( $min_amount ) ) { $order->update_meta_data( '_free_shipping_min_amount', $min_amount ); $order->save(); } } }
How do I achieve my goal? Thanks in advance.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Save Free Shipping Minimum Order Amount to Order’ is closed to new replies.