I’m in search of a technique to conditionally show a picture inside sure Woocommerce hooks that I select primarily based on whether or not a price is true inside a {custom} meta discipline for the merchandise on my web site.
For instance, if my {custom} meta worth for a product is “X”, then I print {custom} html (containing a picture) for the Woocommerce hooks ‘woocommerce_product_additional_information’ and ‘woocommerce_after_shop_loop_item’. Nevertheless if the meta worth is empty, then no picture is printed for a selected product publish.
Thus far that is the code I have been attempting to make work inside my theme’s capabilities.php file for a single hook. The ‘add_action’ perform works for displaying pictures inside a hook, however I can not determine find out how to get the if assertion to work.
if ( get_post_meta($post_id->ID, 'my-custom-meta-field', true) ) :
add_action( 'woocommerce_product_additional_information', 'print_custom_html' );
perform
print_custom_html
(){ ?> <img src="picture.jpg" alt="Picture Identify"> <?php }
endif;
My questions:
-
How can I conditionally run the ‘add_action’ perform primarily based on whether or not my {custom} product meta has a price of ‘X’ or not?
-
How can I customise my ‘add_action’ perform to work with multiple Woocommerce hooks?
Many thanks!