[英]How to show SKU before woocommerce product title on archive page
I'm trying to show the SKU before title of product in woocommerce.我试图在 woocommerce 中的产品标题之前显示 SKU。 Here is a code what I'm trying bellow code show the SKU after price on Woocommerce archive page.
这是我正在尝试的代码,下面的代码在 Woocommerce 存档页面上显示价格后的 SKU。 But is there any hook available to show it before the product title on archive page ?
但是在存档页面上的产品标题之前是否有任何钩子可以显示它?
I use woocommerce_get_price_html
this hook to show it after price I also try the_title
but it override the menu also.我使用
woocommerce_get_price_html
这个钩子在价格后显示它我也尝试了the_title
但它也覆盖了菜单。
function rupom_custom_price_sku( $price ) {
global $woocommerce , $product;
$sku = $product->get_sku();
if (is_shop() || is_product_category() || is_product_tag()){
return $price . '<br /><span class="price-sku" style="color:red">Item # ' . $sku . '</span>';
}
else {
return $price;
}
}
add_filter( 'woocommerce_get_price_html', 'rupom_custom_price_sku' );
woocommerce_before_shop_loop_item_title
is the hook you need to use woocommerce_before_shop_loop_item_title
是你需要使用的钩子
add_action( 'woocommerce_before_shop_loop_item_title', 'custom_before_title' );
function custom_before_title() {
global $product;
if ( $product->get_sku() ) {
echo $product->get_sku();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.