Thanks but how I can implement this conditionally getting the post id problematically and not manually placing them in array? Let me explain.
I am allowing users to add custom badge via custom field value. Now when they have the value, that sales icon does not matter in a sense, so it must be removed. How I can achieve this. I am echoing the badge this way
add_action('woocommerce_before_shop_loop_item', 'ac_wc_show_custom_fields', 20);
function ac_wc_show_custom_fields(){
global $post;
if (get_post_meta( $post->ID, 'ac_custom_badge', true )!==''){
echo '<div class="ac-loop-cus-badge">' .get_post_meta( $post->ID, 'ac_custom_badge', true ) . '</div>';
}
}
Now as you can see the custom badge value is being showing, I need to hide the default Sales badge. Please have a look at the image https://i.imgur.com/1OWmLQK.png
I need to apply css or jquery conditionally but I am not getting this done. I tried with
function ac_wc_show_custom_fields(){
global $post;
if (get_post_meta( $post->ID, 'ac_custom_badge', true )!==''){
echo '<div class="ac-loop-cus-badge">' .get_post_meta( $post->ID, 'ac_custom_badge', true ) . '</div>';
echo '<style>.onsale{display:none;}</style>';
}
}
But the css display:none
is being applied on all the products sales badge making them hidden even though the user has not created the custom badge using the custom field.
Please advise. Thanks