Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active June 1, 2024 11:04
Show Gist options
  • Save braddalton/64ef2451a3e16cf3ce7bb1f86f0b55f8 to your computer and use it in GitHub Desktop.
Save braddalton/64ef2451a3e16cf3ce7bb1f86f0b55f8 to your computer and use it in GitHub Desktop.
Minimum Order Total for Free Pickup in WooCommerce https://wpsites.net/product-tag/woocommerce_package_rates/
function conditionally_hide_local_pickup( $rates, $package ) {
$minimum_amount = 50; // Set your minimum order amount here
// Get the cart total
$cart_total = WC()->cart->get_displayed_subtotal();
// Check if cart total is less than the minimum amount
if ( $cart_total < $minimum_amount ) {
// Loop through the available shipping methods
foreach ( $rates as $rate_id => $rate ) {
// Check if the shipping method is local pickup
if ( 'local_pickup' === $rate->method_id ) {
// Remove local pickup from the available shipping methods
unset( $rates[$rate_id] );
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'conditionally_hide_local_pickup', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment