Reputation: 43
I want to default DHL. But it doesn't work, why is that? In WooCommerce from WordPress.
You can see here: img. Way - functions.php
function reset_default_shipping_method( $method, $available_methods ) {
if ( ! empty( $method ) ) {
return $method;
}
$method = 'shipping_method_0_flat_rate9';
return $method;
}
add_filter('woocommerce_shipping_chosen_method', 'reset_default_shipping_method', 10, 2);
Upvotes: 0
Views: 833
Reputation: 101
The filter has been updated you should try this. I've tested it and it works for me.
Also, the default shipping is stored in your session so if you want to test it you can try from a new browser or log out and log back in.
function prefix_reset_default_shipping_method( $default, $package, $chosen_method ) {
if( $default !== 'flat_rate:9')
$default = 'flat_rate:9';
return $default;
}
add_filter('woocommerce_shipping_chosen_method', 'prefix_reset_default_shipping_method', 10, 3);
Upvotes: 1
Reputation: 108
function reset_default_shipping_method( $method, $available_methods ) {
$default_method = 'wf_fedex_woocommerce_shipping:FEDEX_GROUND'; //provide here the service name which will selected default
if( array_key_exists($method, $available_methods ) )
return $default_method;
else
return $method;
}
add_filter('woocommerce_shipping_chosen_method', 'reset_default_shipping_method', 10, 2);
Add this to your theme's functions.php changing the $default_method var.
source: https://www.xadapter.com/set-default-shipping-method-woocommerce/
Upvotes: 0