我希望woocommerce在每种产品的产品信息下显示产品的品牌
可能吗?
提前致谢 的Morten
wordpress 3.9.1 woocommerce 2.1.10
答案 0 :(得分:1)
以下内容适用于WooCommerce单品页。
最简单的方法是创建名为" Brands"的WooCommerce产品类别。并将您的品牌列为子类别。
-Brands
--apple
--Microsoft
--Google
您需要检查品牌类别" Apple"例如,对你的产品。跳过检查"品牌"但是。
接下来你需要一个钩子来显示" Brands"的检查子类别。在你的产品下。
一个这样的钩子是:woocommerce_after_single_product()
还有其他here - WooCommerce挂钩参考
在functions.php文件或插件中,添加以下代码。
add_action('woocommerce_after_single_product', 'my_woocommerce_after_single_product' );
function my_woocommerce_after_single_product () {
global $product;
$taxonomy = 'product_cat';
$slug = 'brand'; //Or whatever the slug of "Brand" is
$term = get_term_by('slug', $slug, $taxonomy);
//Gets the ID of the Parent category
$term_id = $term->term_id;
//Get the Child terms
$brand_terms = wp_get_post_terms( $product->id, $taxonomy, array("fields" => "all") );
foreach ($brand_terms as $brand_item) {
// Hunt out the child term that is a child of the parent
if ( $brand_item->parent == $term_id ) {
//Get the name of the brand
$brand = $brand_item->name;
break; //Assumes you've only assigned one Brand
}
}
echo '<p>The Brand is: ' . $brand; //Apple or Microsoft or Google...
}
(如果有效,请将其标记为&#34;已回答&#34;)