• Resolved cochii

    (@cochii)


    I want checked by default, the first available delivery method for a user (depending on the user’s status, the first available delivery method is not the same).
    I tried that

    function default_method( $method, $available_methods ) {
        $methods = array();
        foreach($available_methods as $meth){
            array_push($methods, $meth->get_instance_id());
        }
        $preferences = array(
            26, 
            4,
            41,
            40,
            34,
            33,
            42,
            37
        );
    
        // Check the preferred options and return it if it's available shipping option.
        foreach ( $preferences as $preference ) {
            if ( in_array( $preference, $methods ) ) {
                return $preference;
            }
        }
        return $method;
    }
    add_filter( 'woocommerce_shipping_chosen_method', 'default_method', 10, 3);

    Each id in $ preferences corresponds to a delivery method id. On the delivery choice page, there is only one of these id’s present
    But it does not work

    How to do please ?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support mouli a11n

    (@mouli)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Plugin Support Thu P. a11n

    (@thup90)

    Hi there,

    I hope you found the previous reply helpful. We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Select delivery methods as default’ is closed to new replies.