Im using this snippet to hide single price if the product is variable. Works fine but not apply on first product variable of loop:
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 );
}
}
Any idea why?
I don't immediately see a problem with your current code, what you can try:
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 );