Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI am trying to craft a code for WooCommerce to set a minimum order amount for specific countries, but I want to let them order if they select "local pickup" as their shipping method. Nevertheless, I can't make it work. I tried to look it up but couldn't find a post which explained it. I hope that you can give me some insights.
Thanks already in advance!
// Set a minimum amount of order based on shipping zone & shipping method before checking out
add_action( 'woocommerce_check_cart_items', 'cw_min_num_products' );
// Only run in the Cart or Checkout pages
function cw_min_num_products() {
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set the minimum order amount, shipping zone & shipping method before checking out
$minimum = 75;
$county = array('CH') || array('LI');
$shipping_method = 'local_pickup';
// Defining var total amount
$cart_tot_order = WC()->cart->total;
// Compare values and add an error in Cart's total amount
// happens to be less than the minimum required before checking out.
// Will display a message along the lines
if( $cart_tot_order < $minimum && in_array( WC()->customer->get_shipping_country(), $county ) && WC()->shipping->get_shipping_methods() != $shipping_method ) {
// Display error message
wc_add_notice( sprintf( '<strong>Sie haben die Mindestbestellmenge von $%s EUR noch nicht erreicht. Geringerer Bestellwert ist nur bei Selbstabholung möglich.</strong>'
. '<br />Ihre derzeitige Bestellmenge ist: $%s.',
$minimum,
$cart_tot_order ),
'error' );
}
}
}
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI am trying to craft a code for WooCommerce to set a minimum order amount for specific countries, but I want to let them order if they select "local pickup" as their shipping method. Nevertheless, I can't make it work. I tried to look it up but couldn't find a post which explained it. I hope that you can give me some insights.
Thanks already in advance!
// Set a minimum amount of order based on shipping zone & shipping method before checking out
add_action( 'woocommerce_check_cart_items', 'cw_min_num_products' );
// Only run in the Cart or Checkout pages
function cw_min_num_products() {
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set the minimum order amount, shipping zone & shipping method before checking out
$minimum = 75;
$county = array('CH') || array('LI');
$shipping_method = 'local_pickup';
// Defining var total amount
$cart_tot_order = WC()->cart->total;
// Compare values and add an error in Cart's total amount
// happens to be less than the minimum required before checking out.
// Will display a message along the lines
if( $cart_tot_order < $minimum && in_array( WC()->customer->get_shipping_country(), $county ) && WC()->shipping->get_shipping_methods() != $shipping_method ) {
// Display error message
wc_add_notice( sprintf( '<strong>Sie haben die Mindestbestellmenge von $%s EUR noch nicht erreicht. Geringerer Bestellwert ist nur bei Selbstabholung möglich.</strong>'
. '<br />Ihre derzeitige Bestellmenge ist: $%s.',
$minimum,
$cart_tot_order ),
'error' );
}
}
}
Share
Improve this question
asked Jul 2, 2020 at 15:05
Philipp DPhilipp D
414 bronze badges
1
|
1 Answer
Reset to default 3Hey just wanted to let you know! I was able to achieve my desired result with this code!
// Set a minimum amount of order based on shipping zone & shipping method before checking out
add_action( 'woocommerce_check_cart_items', 'cw_min_num_products' );
// Only run in the Cart or Checkout pages
function cw_min_num_products() {
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set the minimum order amount, shipping zone & shipping method before checking out
$minimum = 75;
$county = array('CH','LI');
$chosen_shipping = WC()->session->get( 'chosen_shipping_methods' )[0];
$chosen_shipping = explode(':', $chosen_shipping);
// Defining var total amount
$cart_tot_order = WC()->cart->subtotal;
// Compare values and add an error in Cart's total amount
// happens to be less than the minimum required before checking out.
// Will display a message along the lines
if( $cart_tot_order < $minimum && in_array( WC()->customer->get_shipping_country(), $county ) && $chosen_shipping[0] != 'local_pickup') {
// Display error message
wc_add_notice( sprintf( '<strong>Sie haben die Mindestbestellmenge von €%s exklusive Versandkosten noch nicht erreicht. Geringerer Bestellwert ist nur bei Selbstabholung möglich.</strong>'
. '<br />Ihre derzeitige Bestellmenge ist: €%s.',
$minimum,
$cart_tot_order ),
'error' );
}
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742296843a4417296.html
$county = array('CH') || array('LI');
is wrong - that's not how you concatenate arrays. Why not just$county = array('CH', 'LI');
? – Rup Commented Jul 2, 2020 at 15:37