I’m using WooCommerce on a site built with Pagelines Framework. I need to have a subtitle/customisable field appear under the product name anywhere it appears in the site. As it is, WooCommerce doesn’t offer that option.
I’ve tried using custom fields but WooCommerce use these too and output a bunch of stuff I don’t want along with my subtitle. If I were to name my custom field “bookauthor” would this code work to display only the custom field I want?
<?php echo get_post_meta($id, "bookauthor", true); ?>
And if so, how do I make my new field output straight after the product title on the front end?
I’ve found the hooks I need in this php file (I think, I don’t know php, which is why I’m asking you):
<?php
/*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/
?>
I know how to filter out but how do I add in the custom field to that list?
Or is there an entirely different way to achieve what I need?
Undying gratitude to anyone who can help.
To answer your first question, getting your
post meta
»bookauthor« this way will echo/display just that. If you are defining the variable$id
in your code right – or you can do it like shown below.The code should answer your second question, how to insert your second title line to the product page via the hook
woocommerce_single_product_summary
. Just add your extra information like this:To have some more comfort with your custom post meta you can do what @pl4g4 and @brasofilo suggested and add a metabox to the product edit screen, but it’s not necessary of course, you seem to know how to do it with the standard wordpress custom fields metabox.
You can add your meta box like this, the code is based on the first example on the add_meta_box wordpress codex page.
You can add an extra metabox to the product post. This meta box should have and input form so u can enter the sub-title, when you have added the metabox save the value in the post_meta when the product is saved, then in the single product page from the woocommerce template use the code
to get it.
you can find info about metaboxess Here And also Here