На данный момент я нашел два кода, которые отлично работают по отдельности. Теперь я пытаюсь объединить эти две функции в одну из-за сообщений об ошибках.
В настоящее время всегда появляется глобальное сообщение об ошибке из-за первой функции, даже если в корзине обнаружены продукты общественного питания, через вторую функцию.
Код: Выделить всё
/**
* Set a minimum order amount for checkout - works fine
*/
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value - 51.50
$minimum = 51.50;
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( '| Ihr Bestellwert muss mindestens %s (inkl.Versandkosten) betragen um eine Bestellung abzugeben. — Ihr aktueller Warenwert liegt bei %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->total )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'Ihr Bestellwert muss mindestens %s (inkl.Versandkosten) betragen um eine Bestellung abzugeben. — Ihr aktueller Warenwert liegt bei %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->total )
), 'error'
);
}
}
}
Код: Выделить всё
add_action( 'woocommerce_check_cart_items', 'minimum_order_amount_for_subcategories' );
function minimum_order_amount_for_subcategories() {
$term_slug = 'catering'; // term_id), $childen_ids);
foreach( WC()->cart->get_cart() as $cart_item ) {
// Check for specific product category children term ids
if ( has_term( $terms_ids, $taxonomy, $cart_item['product_id'] ) ) {
$found = true; // At least subcategory is found
// Get non discounted subtotal including taxes from subcategories
$subtotal += $cart_item['line_subtotal'] + $cart_item['line_subtotal_tax'];
}
}
if ( $found && $subtotal < $threshold ) {
wc_add_notice( sprintf(
__( "Bestellwert muss mindestens %s der Kategorie %s betragen", "woocommerce" ),
wc_price($threshold),
'"[b]' . ucfirst($term_slug) . '[/b]"'
), 'error' );
}
}
Mazze
Подробнее здесь: https://stackoverflow.com/questions/698 ... y-catering
Мобильная версия