Skip to content

Instantly share code, notes, and snippets.

@bryceadams
Last active April 14, 2017 10:16
Show Gist options
  • Save bryceadams/9d469b7c297db5aebad9 to your computer and use it in GitHub Desktop.
Save bryceadams/9d469b7c297db5aebad9 to your computer and use it in GitHub Desktop.
Restricts WooCommerce local pickup for minimum order amount
/**
* Restricts WooCommerce local pickup for minimum order amount
* Change $min_amount to the integer amount you want to set as the minimum.
*/
add_filter( 'woocommerce_shipping_local_pickup_is_available', 'wcs_pickup_min_amount', 10, 2 );
function wcs_pickup_min_amount( $is_available ) {
if ( ! $is_available ) {
return $is_available;
}
$has_met_min_amount = false;
$min_amount = 40;
if ( WC()->cart->prices_include_tax ) {
$total = WC()->cart->cart_contents_total + array_sum( WC()->cart->taxes );
} else {
$total = WC()->cart->cart_contents_total;
}
if ( $total >= $min_amount ) {
$has_met_min_amount = true;
}
return $has_met_min_amount;
}
@dora-nan
Copy link

Hi,
That's a great code. But I need to display an error message when $min_amount < 40.
Could you suggest me please?
Thank you.

@valeriu
Copy link

valeriu commented Oct 14, 2016

Thank you @bryceadams!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment