是的,这是个坏主意,因为这不是正确的方法…显然,您使用的是一个名为test_loop_price()
的定制函数,并且在您的问题中没有提供该函数的代码.
首先从loop/price.php
模板文件中删除您的自定义代码.
然后,您需要以WooCommerce产品循环为目标,在该函数中如下所示:
add_filter( 'woocommerce_format_sale_price', 'test_loop_price', 10, 3 );
function test_loop_price( $price, $regular_price, $sale_price ) {
global $woocommerce_loop, $product;
if ( ( is_product() && isset($woocommerce_loop['name']) && empty($woocommerce_loop['name']) ) ) {
return $price;
}
## Here below comes your existing code ##
return $price;
}
代码放在子主题的functions.php文件中(或插件中).测试和作品.