Php WooCommerce:显示活动属性的描述
WooCommerce允许您编写属性描述,但它不会显示在任何地方 我想在分类页面上显示这个属性描述,但只有一种类型的属性被选中时(pa_颜色) 解决方案如下。希望能为你节省一些时间Php WooCommerce:显示活动属性的描述,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,WooCommerce允许您编写属性描述,但它不会显示在任何地方 我想在分类页面上显示这个属性描述,但只有一种类型的属性被选中时(pa_颜色) 解决方案如下。希望能为你节省一些时间 /* /* * If color filter active, show its attribute description on the Archive page */ add_action('woocommerce_archive_description', 'custom_attribute_descripti
/*
/*
* If color filter active, show its attribute description on the Archive page
*/
add_action('woocommerce_archive_description', 'custom_attribute_description');
function custom_attribute_description() {
global $_chosen_attributes;
if ( isset($_chosen_attributes['pa_color']) ) {
$_chosen_color_id = $_chosen_attributes['pa_color']['terms'][0];
// Prevent non-number IDs from being used
$_chosen_color_id = preg_replace('/\D/', '', $_chosen_color_id);
$_chosen_color_details = get_term( $_chosen_color_id, 'pa_color' );
echo '<div class="chosen-color-description">';
echo '<strong>' . $_chosen_color_details->name . '</strong>: ';
echo $_chosen_color_details->description;
echo '</div>';
}
}
*如果颜色过滤器处于活动状态,则在存档页面上显示其属性说明
*/
添加_操作('woocommerce_archive_description'、'custom_attribute_description');
函数自定义属性描述(){
全局$所选属性;
如果(isset($_selected_attributes['pa_color'])){
$_selected_color_id=$_selected_属性['pa_color']['terms'][0];
//防止使用非数字标识
$\u selected\u color\u id=preg\u replace('/\D/','',$\u selected\u color\u id);
$\u selected\u color\u details=get\u term($\u selected\u color\u id,'pa\u color');
回声';
回显“”。$\u选择的颜色\u详细信息->名称。“:”;
echo$\所选颜色\详细信息->说明;
回声';
}
}