【问题标题】:How to check if a product is not a bundled product in WooCommerce如何检查产品是否不是 WooCommerce 中的捆绑产品
【发布时间】:2020-10-02 14:48:58
【问题描述】:

我想用这个sn-p来替换产品的标题。这行得通。

  /** 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 
  }

但我想弄清楚如果产品类型不是捆绑产品(来自https://woocommerce.com/products/product-bundles/),如何只运行这个sn-p(替换所有其他产品上的标题)。

有人可以帮帮我吗?

【问题讨论】:

    标签: php wordpress woocommerce product woocommerce-product-bundles


    【解决方案1】:

    更新

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

    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
    }
    

    代码在您的活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 2021-12-04
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      相关资源
      最近更新 更多