如何检查产品是否不是 WooCommerce 中的捆绑产品

use*_*894 1 php wordpress product woocommerce woocommerce-product-bundles

我想用这个片段来替换产品的标题。这样可行。

  /** 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 
  }
Run Code Online (Sandbox Code Playgroud)

但我试图弄清楚如果产品类型不是捆绑产品(来自https://woocommerce.com/products/product-bundles/ ),如何仅运行此代码片段(替换所有其他产品上的标题) 。

有人可以帮我一点吗?

Loi*_*tec 5

更新

尝试使用类似的东西(将您的代码限制为“捆绑”产品类型之外的其他产品):

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
}
Run Code Online (Sandbox Code Playgroud)

代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。