本篇文章更新時間:2020/10/17
如有資訊過時或語誤之處,歡迎使用 Contact 功能通知。
一介資男的 LINE 社群開站囉!歡迎入群聊聊~
如果本站內容對你有幫助,歡迎使用 BFX Pay 加密貨幣 或 新台幣 贊助支持。
亂逛看到的功能,頗簡單又實用!
於(子)主題裡的 functions.php
檔案中加入下方程式碼片段(或可以使用 Code Snippets 這隻外掛來處理。):
function mxp_custom_sale_flash($text, $post, $product) {
global $product;
$percentage = round((($product->regular_price - $product->sale_price) / $product->regular_price) * 100);
return '' . $percentage . '%';
}
add_filter('woocommerce_sale_flash', 'mxp_custom_sale_flash', 10, 3);
就能在特價商品的標籤上顯示這個折扣的百分比了!
至於還想要改成其他種顯示做法也是直接從上面的程式碼範例去下手調整。
Ref: How can I change woocommerce_sale_flash from Text to Discount Percentage
請問這段是要加在哪裡?謝謝
加在(子)主題裡的 functions.php 檔案哦! 也可以使用 https://tw.wordpress.org/plugins/code-snippets/ 這隻外掛來處理。