I am struggling with getting the meta data to filter properly through my functions.php.
I can get this to work if I edit the meta.php in my child theme with no problem: (short story - but because I am using Avada Theme - and they change the location of the child theme on an upgrade, I am opting for the functions.php)
I am currently trying to filter the meta this way:
add_filter ('woocommerce_product_meta_start','add_pet_info' );
function add_pet_info($pet_info) {
$string ="Test Text";
return $pet_info . $string; }
And I would like to get this result: But I just cant get it to work.
Any ideas what I am missing here?
Thanks!
woocommerce_product_meta_start
is not a filter. It's an action. So if you return
a value to is, nothing is going to happen. This should print out "Test Text" before Woo prints any of its meta.
add_action('woocommerce_product_meta_start','add_pet_info' );
function add_pet_info($pet_info) {
_e( "Test Text", "your-textdomain" );
}
Unsure of where exactly you are trying to add the code, but keep in mind that you can add it to any hook available in WooCommerce (or any hook available in your theme).
For example to put the test text below the product meta you could modify the above to the following:
add_action('woocommerce_product_meta_end','add_pet_info' );
function add_pet_info($pet_info) {
_e( "Test Text", "your-textdomain" );
}
Anywhere you see a do_action
you are looking at an action hook that you can attach functions to via add_action()
.