mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/65473979/display-message-if-any-cart-item-has-quantity-of-1-in-woocommerce-cart
19 lines
755 B
Text
19 lines
755 B
Text
add_action( 'woocommerce_before_cart_contents', 'display_notice_based_on_item_quantity' );
|
|
function display_notice_based_on_item_quantity() {
|
|
foreach ( WC()->cart->get_cart() as $cart_item ) {
|
|
if ( $cart_item['quantity'] == 1 )
|
|
{
|
|
$terms = get_the_terms( $cart_item['product_id'], 'product_cat' );
|
|
foreach ( $terms as $term )
|
|
{
|
|
if ($term->slug == 'your-category-slug')
|
|
continue 2;
|
|
}
|
|
if ( is_cart() )
|
|
echo '<div class="cart-qty-notice">';
|
|
printf( __("Message goes here", "woocommerce"));
|
|
echo '</div>';
|
|
break;
|
|
}
|
|
}
|
|
}
|