• Resolved Benjamin Pau

    (@soapking)


    I’m trying to save the minimum order amount for free shipping to order data regardless of the shipping method chosen.

    1. The minimum order amount for free shipping is different in every shipping zone segregated through post codes.
    2. The user is unable to select the shipping method.
    3. The flat rate is chosen by default if the minimum order amount for free shipping is not achieved.
    4. 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.

    • This topic was modified 10 months, 3 weeks ago by Benjamin Pau.
Viewing 1 replies (of 1 total)
  • Hi Benjamin,

    Thank you for reaching out to WooCommerce support. I understand you are having trouble with saving the free shipping minimum order amount to order data.

    Unfortunately, this is a custom coding question that is beyond the scope of our support policy. Please note that writing or providing custom code is not within the scope of our support policy. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    We appreciate your understanding and cooperation. Thank you for choosing WooCommerce.

Viewing 1 replies (of 1 total)
  • The topic ‘Save Free Shipping Minimum Order Amount to Order’ is closed to new replies.