How to check if a product is not a bundled product in WooCommerce

2.9k Views Asked by At

I want to use this snippet to replace the titles of products. That works.

  /** Remove the shop loop title link and replace with brand **/ 
  remove_action( 'woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title', 10 );
  add_action('woocommerce_shop_loop_item_title', 'abChangeProductsTitle', 10 );

  function abChangeProductsTitle() { ?>
      <p class="name product-title custom-brand" style="height: 23px;">
      <?php echo strip_tags ( get_the_term_list( $post->ID, 'product_brand', '', ', ', ''  ) ); ?> 
  </p><?php 
  }

But I am trying to figure out how to only run this snippet (replace titles on all other products) if the product type is not a bundled product (from https://woocommerce.com/products/product-bundles/ ).

Can someone help me along a little?

1

There are 1 best solutions below

0
LoicTheAztec On BEST ANSWER

Updated

Try to use something like (to restrict your code to other products than "bundle" product type):

add_action('woocommerce_shop_loop_item_title', 'change_product_title_except_bundle_products', 1 );
function change_product_title_except_bundle_products(){
    global $product;

    // Except for bundle products type
    if( ! $product->is_type('bundle') ) {
        remove_action( 'woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title', 10 );
        add_action('woocommerce_shop_loop_item_title', 'customize_product_title', 10 );
    }
}

function customize_product_title() {
    $brands = get_the_term_list( get_the_id(), 'product_brand', '', ', ', ''  );
    ?>
    <p class="name product-title custom-brand" style="height: 23px;"><?php echo strip_tags ( $brands ); ?> </p><?php
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.