Select delivery methods as default
-
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 thatfunction 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 workHow to do please ?
Thanks
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Select delivery methods as default’ is closed to new replies.