【问题标题】:Woocommerce specific banner product category and childsWoocommerce 特定横幅产品类别和子项
【发布时间】:2017-05-30 08:50:46
【问题描述】:

我已经搜索了很多,但我没有找到任何具体的,或者至少,我的开发技能还不是很好,如果有人可以帮助我感激的话。

我的目标是在类别 X 或同一 X 的子类别内的每个产品上显示文本。

例如: 水果 -香蕉

如果波纹管产品在 Bananas 内,它也会显示代码,因为它属于 Fruits。

add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){

    if ( is_product_category(array(140,20)) )
        $post_excerpt = $post_excerpt. '<br><div class="product-message"><p>' . __( "Whats the measure? <a href='/#right-measure' target='_blank'>Check</a>.", "woocommerce" ) . '</p></div>'; 

    return $post_excerpt;
}

我知道我的代码不好,因为每次客户添加子类别时我都必须修复它...

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    我做到了:

    add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
    function single_product_short_description( $post_excerpt ){
    global $post;
    $terms = wp_get_post_terms( $post->ID, 'product_cat' );
    foreach ( $terms as $term ) $categories[] = $term->slug;
    
    if ( in_array( 'piercings', $categories ) || in_array( 'piercings-en', $categories ) ) {
      $post_excerpt = $post_excerpt. '<br><div class="product-message"><p>' . __( "Bla bla bla", "woocommerce" ) . '</p></div>';
    }
    
    return $post_excerpt;
    }
    

    希望这对某人有所帮助

    【讨论】:

      猜你喜欢
      • 2014-09-19
      • 2014-09-21
      • 2017-06-04
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多