在 woocommerce 中,我想在商店页面的产品标题下显示一些产品属性。该产品属性为“年份”、“型号”和“油品”。
这就是我现在所拥有的:
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 文件中。经过测试并有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)