使用 Woocommerce,我使用以下代码成功地从产品档案页面中删除了销售徽章和价格:
\n\n// Remove Sales Flash\nadd_filter('woocommerce_sale_flash', 'woo_custom_hide_sales_flash');\nfunction woo_custom_hide_sales_flash()\n{\n return false;\n}\n\n// Remove prices on archives pages\nremove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );\nRun Code Online (Sandbox Code Playgroud)\n\n所有产品都是可变产品,所有变体的价格相同。实际上所有价格都是促销价。
\n\n我想在单个产品页面中的每个可变价格范围后添加折扣百分比。我尝试使用以下代码:
\n\nadd_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );\nfunction woocommerce_custom_sales_price( $price, $product ) {\n $percentage = round( ( ( $product->regular_price \xe2\x80\x93 $product->sale_price ) / \n $product->regular_price ) * 100 );\n return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但我什么也没得到
\n\n我做错了什么,该怎么办?
\n\n对此的任何帮助将不胜感激。
\n