woocommerce conditional

1 Reply ·

  1. I have, mainly from the Woocommerce help pages, (and an added conditional)

    /**
    * Add featured product description above product
    * Output description tab template using 'woocommerce_before_single_product' hook
    */
    add_action( 'woocommerce_before_single_product', 'railtrail_woocommerce_template_featured_product_description', 20 );
    
    function railtrail_woocommerce_template_featured_product_description() {
      if ( is_product() && has_term ( 'raffles', 'product_cat' ) ) {
    
    get_template_part( 'woo/featured', 'description' );
     }
    }
    

    which works and the conditional ( if ( is_product() && has_term ( 'raffles', 'product_cat' ) ) ) works as expected

    and

    // disable the magnification zoom in product images
    add_action( 'template_redirect', function() {
      if ( is_product() && has_term ( 'raffles', 'product_cat' ) ) {
        remove_theme_support( 'wc-product-gallery-zoom' );
        remove_theme_support( 'wc-product-gallery-lightbox' );
        remove_theme_support( 'wc-product-gallery-slider' );
    }
    }, 100 );
    

    which works and the conditional ( if ( is_product() && has_term ( 'raffles', 'product_cat' ) ) ) works as expected.

    The following works in that it removes the description tab and contents as expected, but the conditional ( if ( is_product() && has_term ( 'raffles', 'product_cat' ) ) ) does not. The description tab and contents are removed on other categories as well as the product_cat 'raffles'

    /**
    * Remove WooCommerce Description Tab
    */
    
    add_filter( 'woocommerce_product_tabs', 'railtrail_woo_remove_product_tabs', 98 );
    
    function railtrail_woo_remove_product_tabs( $tabs ) {
      if ( is_product() && has_term ( 'raffles', 'product_cat' ) ) {
    
        unset( $tabs['description'] );       
    
        return $tabs;
      }
    
    }
    

    Can you suggest a fix?

  2. markmcl

    And after looking at this for a day, I fixed it straight after posting

    /**
     * Remove product data tabs
     */
    add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
    
    function woo_remove_product_tabs( $tabs ) {
      if ( is_product() && has_term ( 'raffles', 'product_cat' ) )
        unset( $tabs['description'] );        // Remove the description tab
        unset( $tabs['reviews'] );      // Remove the reviews tab
        unset( $tabs['additional_information'] );   // Remove the additional information tab
    
        return $tabs;
    }