wordpress - 商店页面上的额外产品信息
解决方案
您应该尝试在每个产品的价格上方显示产品类别。
add_filter( 'woocommerce_get_price_html', 'woo_shipping_with_price_display' );
add_filter( 'woocommerce_cart_item_price', 'woo_shipping_with_price_display' );
function woo_shipping_with_price_display( $price ) {
$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
$text = '';
if ( $product_cats && ! is_wp_error ( $product_cats ) ){
$single_cat = array_shift( $product_cats );
$text = '<div itemprop="name" class="product_category_title"><span>'.__(esc_attr($single_cat->name)).'</span></div>';
}
if ($price == true) {
return $text . $price;
}
else {
return $text;
}
}
您可以从以下行更改/更新 html、class 等:
$text = '<div itemprop="name" class="product_category_title"><span>'.__(esc_attr($single_cat->name)).'</span></div>';
推荐阅读
- openmdao - OpenMDAO:如何处理 ExplicitComponent.compute 中的非收敛点?
- firebase - 从 Firebase 到 BigQuery 的实时或每小时数据同步
- ruby - 通过ruby脚本进行mongo查询需要很长时间执行
- php - 从表中选择短划线之间的数据
- asp.net-mvc - 如何在脚本部分调用局部视图
- bash - 用 sed 替换包含反斜杠(\)的单词
- asp.net-core - 使用 ASP.Net Core Web 应用程序设置 Jasmine
- unit-testing - java.lang.AssertionError:预期:
但是是: - angular5 - Angular 6 迁移 PWA 不起作用
- android - 小于 4MB 的即时应用程序