如果产品是可变的,我将使用此代码段来隐藏单一价格。工作正常,但不适用于循环的第一个产品变量:
add_action( 'woocommerce_after_shop_loop_item_title', 'hide_single_price' );
function hide_single_price() {
global $product;
if ( $product->is_type( 'variable' ) ) {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
知道为什么吗?
答案 0 :(得分:1)
我没有立即发现您当前的代码有问题,您可以尝试:
function hide_single_price() {
// Get the global product object
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
if ( $product->is_type( 'variable' ) ) {
// Debug purposes, delete afterwards!!
echo 'DEBUG!';
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'hide_single_price', 5 );