Skip to content

Instantly share code, notes, and snippets.

@KeylorCR
Created March 10, 2021 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeylorCR/f4fd4fbc85f706fb833895daf4054475 to your computer and use it in GitHub Desktop.
Save KeylorCR/f4fd4fbc85f706fb833895daf4054475 to your computer and use it in GitHub Desktop.
<?php
/**
* Change shipping method priority
* Use array_unshift for the beginnig and array_push onto the end of array
*/
function kmchild_sort_shipping_methods($available_shipping_methods, $package) {
if (isset($available_shipping_methods['wc_pickup_store'])) {
$wc_pickup_store = $available_shipping_methods['wc_pickup_store'];
unset($available_shipping_methods['wc_pickup_store']);
// array_unshift($available_shipping_methods, $wc_pickup_store); // Prepend element to the beginning of array
array_push($available_shipping_methods, $wc_pickup_store); // Push element onto the end of array
}
return $available_shipping_methods;
}
add_filter('woocommerce_package_rates', 'kmchild_sort_shipping_methods', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment