Advertisement
borkolivic

Prikaz custom obavijesti u košarici, ovisno o kategoriji proizvoda

Jun 17th, 2021
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. add_action( 'woocommerce_before_cart', 'mx_notice_for_category_in_cart' );
  2.  
  3. function mx_notice_for_category_in_cart() {
  4.  
  5.    $category_in_cart = false;
  6.  
  7.    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  8.  
  9.       // Upiši "slug" kategorije za koju želiš prikaz obavijesti
  10.       if ( has_term( 'posebna-kategorija', 'product_cat', $cart_item['product_id'] ) ) {
  11.          $category_in_cart = true;
  12.          break;
  13.       }
  14.    }
  15.  
  16.    if ( $category_in_cart ) {
  17.       wc_print_notice( 'Proizvod u posebnoj kategoriji je u košarici', 'notice' );
  18.    }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement