Php 在Woocommerce归档页面上的“阅读更多”按钮中显示品牌标签
在Woocommerce,我是用来处理产品品牌的。我想在woocommerce阅读更多按钮中显示品牌标签 这是我的代码:Php 在Woocommerce归档页面上的“阅读更多”按钮中显示品牌标签,php,wordpress,button,woocommerce,custom-taxonomy,Php,Wordpress,Button,Woocommerce,Custom Taxonomy,在Woocommerce,我是用来处理产品品牌的。我想在woocommerce阅读更多按钮中显示品牌标签 这是我的代码: // Shop Catalog mode if ( zget_option( 'woo_catalog_mode', 'zn_woocommerce_options', false, 'no' ) == 'yes' ) { remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_
// Shop Catalog mode
if ( zget_option( 'woo_catalog_mode', 'zn_woocommerce_options', false, 'no' ) == 'yes' ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
// Add the read more button
// Fixes #917
add_action( 'woocommerce_after_shop_loop_item', 'zn_woocommerce_more_info' );
function zn_woocommerce_more_info(){
echo '<span class="kw-actions">';
echo '<a class="actions-moreinfo" href="'.get_permalink().'" title="'. __( "MORE INFO", 'zn_framework' ).'">';
if ( zget_option( 'woo_prod_layout', 'zn_woocommerce_options', false, 'classic' ) == 'style2' ) {
echo '<svg width="50px" height="24px" class="svg-moreIcon"><circle cx="12" cy="12" r="2"/><circle cx="20" cy="12" r="2"/><circle cx="28" cy="12" r="2"/></svg>';
} else {
echo __( "MORE INFO", 'zn_framework' );
}
echo '</a>';
echo '</span>';
}
}
//商店目录模式
如果(zget_选项('woo_目录_模式','zn_目录_选项',false,'no')=='yes'){
删除操作('woocommerce'u在'u shop'u loop'u item'之后,'woocommerce'模板'u loop'u将'u添加到'u cart');
删除操作('woocommerce\u single\u product\u summary'、'woocommerce\u template\u single\u add\u to\u cart',30);
//添加“阅读更多”按钮
//修复#917
添加动作('woocommerce'在'shop'循环'item'之后,'zn'woocommerce'更多信息');
函数zn\u woocommerce\u more\u info(){
回声';
回声';
回声';
}
}
我需要用woocommerce归档页面中每个产品的特定品牌替换“阅读更多”文本
非常感谢您的帮助。要在挂钩功能中获取当前产品的YITH brands标签,您将使用:
// Get the YITH brands tags (array of term names)
$brands = wp_get_post_terms( get_the_id(), 'yith_product_brand', array( 'fields' => 'names' ) );
// Convert the array to a string (with coma separated brand tags)
$brands = implode(', ', $brands);
// Get the YITH brands tags (array of term names)
$brands = wp_get_post_terms( get_the_id(), 'yith_product_brand', array( 'fields' => 'names' ) );
// Convert the array to a string
$brand = reset($brands);
或者,如果您的产品设置了独特的品牌,您将使用:
// Get the YITH brands tags (array of term names)
$brands = wp_get_post_terms( get_the_id(), 'yith_product_brand', array( 'fields' => 'names' ) );
// Convert the array to a string (with coma separated brand tags)
$brands = implode(', ', $brands);
// Get the YITH brands tags (array of term names)
$brands = wp_get_post_terms( get_the_id(), 'yith_product_brand', array( 'fields' => 'names' ) );
// Convert the array to a string
$brand = reset($brands);
现在,您可以在挂钩函数中轻松包含此代码,以替换“阅读更多”文本:
add_action('woocommerce_在_shop_loop_item之后,'zn_woocommerce_more_info');
函数zn\u woocommerce\u more\u info(){
回声';
$brands=wp_get_post_terms(获取_id(),'yith_product_brand',数组('fields'=>'names');
$brand=重置($brands);
回声';
回声';
}
如果您使用Woocommerce Brands插件,则必须将代码中的“yith\u product\u brand”替换为“product\u brand”
。就这些
相关回答:您使用什么插件来创建品牌?此外,您的代码具有自定义函数,如zget_option()和zn_woocommerce_more_info(),没有人能猜到,因此您的代码不可测试…我使用的是YITH Brands附加组件