在woocommerce产品页面上显示品牌
我想让woocommerce在每个产品的产品信息下显示产品的品牌 可能吗 提前谢谢 莫顿 wordpress 3.9.1在woocommerce产品页面上显示品牌,woocommerce,Woocommerce,我想让woocommerce在每个产品的产品信息下显示产品的品牌 可能吗 提前谢谢 莫顿 wordpress 3.9.1 woocommerce 2.1.10以下内容适用于woocommerce单一产品页面 最简单的方法是创建一个名为“品牌”的WooCommerce产品类别,并将您的品牌列为子类别 -品牌 --苹果 --微软 --谷歌 例如,你可以在你的产品中选择品牌类别“苹果”。但是,跳过检查“品牌” 接下来,您需要一个钩子,它将在您的产品下显示选中的“品牌”子类别 一个这样的钩子是:wooc
woocommerce 2.1.10以下内容适用于woocommerce单一产品页面 最简单的方法是创建一个名为“品牌”的WooCommerce产品类别,并将您的品牌列为子类别 -品牌
--苹果
--微软
--谷歌 例如,你可以在你的产品中选择品牌类别“苹果”。但是,跳过检查“品牌” 接下来,您需要一个钩子,它将在您的产品下显示选中的“品牌”子类别 一个这样的钩子是:
woocommerce\u-after\u-single\u-product()
还有其他的参考资料
在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...
}
add_action('woocommerce_在单个产品之后,'my_-woocommerce_在单个产品之后)';
单产品之后的功能my\u woocommerce\u(){
全球$产品;
$taxonomy='product_cat';
$slug='brand';//或者不管“brand”的slug是什么
$term=get_term_by('slug',$slug,$taxonomy);
//获取父类别的ID
$term\u id=$term->term\u id;
//得到孩子们的条件
$brand_terms=wp_get_post_terms($product->id,$taxonomy,array(“fields”=>“all”));
foreach($brand_术语作为$brand_项目){
//找出父项的子项
如果($brand\u item->parent==$term\u id){
//获取品牌名称
$brand=$brand\u项目->名称;
break;//假设您只指定了一个品牌
}
}
echo'品牌是:'.$Brand;//苹果、微软或谷歌。。。
}
(如果有效,请将其标记为“已回答”)