• Resolved Web Expert

    (@seldimi)


    Hello.
    I’m trying to change the ordering of shipping methods by putting wc_pickup_store on the bottom of the shipping method list with the help of the following array:

    add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );
    function hide_shipping_method_based_on_shipping_class( $rates, $package )
    {
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        if (isset($rates['wc_pickup_store'])) {
            $wc_pickup_store = $rates['wc_pickup_store'];
            unset($rates['wc_pickup_store']);
            array_push($rates,$wc_pickup_store);
        }
        return $rates;
    }

    The issue is that while it’s moved, when selected, the wc-pickup-store select box is not appearing.
    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Web Expert

    (@seldimi)

    The reason the above was not working is that array_push doesn’t give the appropriate key to $rates table. Posting my resolved solution.

    add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );
    function hide_shipping_method_based_on_shipping_class( $rates, $package )
    {
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        if (isset($rates['wc_pickup_store'])) {
            $wc_pickup_store = $rates['wc_pickup_store'];
            unset($rates['wc_pickup_store']);
            $rates['wc_pickup_store']=$wc_pickup_store;
        }
        return $rates;
    }
    Plugin Author Keylor Mendoza

    (@keylorcr)

    Hey @seldimi

    Thank you for your request and also for posting the solution to anyone else here.

    Best regards!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change ordering with woocommerce_package_rates’ is closed to new replies.