【问题标题】:How to add tags to code snippets?如何在代码片段中添加标签?
【发布时间】:2018-10-20 10:25:06
【问题描述】:

我白天很努力地添加和标签,但没有达到预期的效果。

有人可以帮我在这段代码sn-p中添加标签和标签吗?

echo wc_get_product_category_list( $product->get_id(), '<span class="meta-sep">,</span> ', '<span class="posted_in">' . _n( 'Category:', 'Categories:' , count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' );

例如:

<th>Category:</th> <td>Kit baby</td>

echo '<th>SKU:</th>' . '<td>' . $product->get_sku() . '</td>';

请帮帮我,谢谢。

【问题讨论】:

  • 上面的代码你想在哪个页面显示?
  • @PPL 我将上述代码用于单个产品页面
  • 表示您要在单个产品页面上显示产品sku。
  • 如果可能,请分享图片,以便我们准确了解。
  • @PPL 我想用 标签显示“类别”,例如“sku”,谢谢prnt.sc/jg2pjk

标签: wordpress function woocommerce hook-woocommerce


【解决方案1】:

显示产品标签:

<?php
$current_tags = get_the_terms( get_the_ID(), 'product_tag' );
if ( $current_tags && ! is_wp_error( $current_tags ) ) {  
    echo '<tr>';
    echo '<th>Tags: </th>';  
    foreach ($current_tags as $tag) {
        $tag_title = $tag->name;
        $tag_link = get_term_link( $tag );
        echo '<td><a href="'.$tag_link.'">'.$tag_title.'</a></td>';
    }
    echo '</tr>';
} ?>

显示产品类别:

<?php
$current_tags = get_the_terms( get_the_ID(), 'product_cat' );
if ( $current_tags && ! is_wp_error( $current_tags ) ) {  
    echo '<tr>';
    echo '<th>Category: </th>';  
    foreach ($current_tags as $tag) {
        $tag_title = $tag->name;
        $tag_link = get_term_link( $tag );
        echo '<td><a href="'.$tag_link.'">'.$tag_title.'</a></td>';
    }
    echo '</tr>';
} ?>

希望这对你有用。

【讨论】:

  • 有什么问题?
  • 你在哪里添加了这个功能?
  • 因为使用上面的代码,我们可以根据需要得到产品标签和类别。
  • 我们可以转到聊天部分吗?
猜你喜欢
  • 2018-12-16
  • 2017-10-01
  • 1970-01-01
  • 2021-03-25
  • 1970-01-01
  • 1970-01-01
  • 2010-09-05
  • 2011-09-16
  • 2017-10-23
相关资源
最近更新 更多