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」 文字替換為您的文字,銷售徽章設計將繼承您的主題風格。