Skip to content
Advertisement

Display a custom field under WooCommerce single product title

I have problem with a custom fields in WooCommerce.

I have tille of product (book) and i want add author with custom field. I done it with register in theme custom fields and i add new one with WordPress custome field.

Custom fields call: product_author (that is my) and mbt_publisher_name (from theme)

I have found the template file title.php in theme and in woocommerce directory.

I tried to add:

JavaScript

and nothing change… orignal source from title.php

JavaScript

what should I do to display that custom field under title?
Where I can find that hook?

Thanks

Advertisement

Answer

If you look at the woocommerce template content-single-product.php you will see this code (starting on line 54):

JavaScript

So woocommerce_template_single_title is hooked in woocommerce_single_product_summary action hook with a priority of 5 (so it comes first).

You can do it in 2 Ways:

1) you can use a custom function hooked in woocommerce_single_product_summary hook with a priority between 6 to 9, this way:

JavaScript

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works on WooCommerce 3.0+


Or

2) You can edit directly the template single-product/title.php located in the WooCommerce folder of your active theme (see below the reference about overriding WooCommerce templates through theme):

JavaScript

Official reference: Template Structure + Overriding WooCommerce Templates via a Theme

I recommend you the first method because it’s cleaner as it uses a hook and you will not need to make any changes if templates are updated. You should also better use a child theme…

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement