WooCommerce 為銷售商品添加銷售徽章,意味着產品銷售價格低於實際價格。默認 WooCommerce,銷售徽章文字是 “促銷!”
默認銷售文字如下所示:
現在打開位於 wp-content/themes/your-theme-name/ 中的主題的 function.php 文件推薦放置到子主題中,並在其末尾添加此代碼:
add_filter('woocommerce_sale_flash', 'vs_change_sale_content', 10, 3);
function vs_change_sale_content($content, $post, $product){
$content = '<span class="onsale">'.__( 'On Sale', 'woocommerce' ).'</span>';
return $content;
}
在 function.php 主題文件中添加上面的過濾器後:
注意:您可以將 “On Sale” 文本替換為您的文字,銷售徽章設計將繼承您的主題風格。