• Resolved Kevin Pryce

    (@kpry44)


    Love this plugin. So good!

    I offer free shipping on all products in a certain product category.

    Using either CSS or a function, is it possible to hide the label entirely if an item assigned to a product category is in the cart?

    Please and thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Kevin Pryce

    (@kpry44)

    Update: I was able to answer my own question with a function:

    /*==========================================================================
    =            HIDE FREE SHIPPING LABEL IF PRODUCT CAT IS IN CART            =
    ==========================================================================*/
    
    add_action( 'wp_head' , 'custom_conditional_css_styles' );
    function custom_conditional_css_styles(){
       if( WC()->cart->is_empty() ) return; // We exit if cart is empty
    
       // HERE your product category
       $product_category = array(
          'sasktel-apple-iphones',
          'sasktel-smartphones',
          'cell-phones',
          'feature-phones',
          'sasktel-apple-ipads'
       );
       $found            = false;
    
       // Loop through cart items checking for our product category
       foreach ( WC()->cart->get_cart() as $cart_item ) {
          if ( has_term( $product_category, 'product_cat', $cart_item['product_id'] ) ) {
             $found = true;
                break; // Found we stop the loop
             }
          }
    
       if ( ! $found ) return; // If the product category is noy found we exit
    
       // Here come your CSS styles
       ?>
       <style>
       .devnet_fsl-free-shipping {
          display: none !important;
       }
    </style>
    <?php
    }
    Plugin Author Marin Matosevic

    (@marinmatosevic)

    Hi Kevin,

    Glad to hear that, and thanks for posting your solution, it will be helpful to others.

    If you like a plugin, feel free to leave a review 🙂

    Best regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditionally hide label if product-cat in cart’ is closed to new replies.