Php 在Woocommerce归档页面的产品标题下显示特定的产品属性
在woocommerce中,我想在商店页面的产品标题下显示一些产品属性。该产品属性为“年”、“型号”和“油” 这就是我现在所拥有的:Php 在Woocommerce归档页面的产品标题下显示特定的产品属性,php,wordpress,woocommerce,product,custom-taxonomy,Php,Wordpress,Woocommerce,Product,Custom Taxonomy,在woocommerce中,我想在商店页面的产品标题下显示一些产品属性。该产品属性为“年”、“型号”和“油” 这就是我现在所拥有的: add_action('woocommerce_shop_loop_item_title', 'wh_insertAfterShopProductTitle', 15); function wh_insertAfterShopProductTitle() { global $product; $abv = $product->get_at
add_action('woocommerce_shop_loop_item_title', 'wh_insertAfterShopProductTitle', 15);
function wh_insertAfterShopProductTitle()
{
global $product;
$abv = $product->get_attribute('pa_year');
if (empty($abv))
return;
echo __($abv, 'woocommerce');
}
非常感谢您的帮助。要在Woocommerce存档页面中的产品标题下显示“年份”、“型号”和“机油”产品属性,请使用以下命令:
add_action('woocommerce_shop_loop_item_title', 'display_attributes_after_product_loop_title', 15);
function display_attributes_after_product_loop_title(){
global $product;
$output = array(); // Initializing
// The year
if( $year = $product->get_attribute('pa_year') ){
// Save the value in the array
$output[] = $year;
}
// The model
if( $model = $product->get_attribute('pa_model') ){
// Save the value in the array
$output[] = $model;
}
// The type of oil
if( $oil = $product->get_attribute('pa_oil') ){
// Save the value in the array
$output[] = $oil;
}
// Output
if( sizeof($output) > 0 ){
// Display product attributes coma separated values (you can change the separator by something else below).
echo implode( ', ', $output);
}
}
代码进入活动子主题(活动主题)的function.php文件。测试和工作