Hi,
I need to show a specific custom field inside woocommerce product summary and I already have a working function (i tried to add simple text and it works as expected):
function add_custom_field_after_title() {
global $product;
$start_date= get_post_meta( $product->get_id(), 'start-date-of-journey', true );
if ( $start_date ) {
echo '<p class="journey-date">' . $start_date . '</p>';
}
}
add_action( 'woocommerce_single_product_summary', 'add_custom_field_after_title', 6 );
Anyway the variable $start_date comes out as empty, the slug of the field I want to show is "start-date-of-journey", is there anything else needed to be able to retrieve that specific value?
In case it's needed, the custom fields group is called "Journey custom fields".
Hi,
Thank you for contacting us and I'd be happy to assist.
In the database, Toolset's custom field values are stored with the key, which has 'wpcf-' prefix appended to the field slug.
If your field's slug is 'start-date-of-journey', in a core WordPress function like 'get_post_meta', you'll use 'wpcf-start-date-of-journey'.
Note: Toolset date type field values are stored in a UNIX timestamp format and you'll need additional PHP code to convert it into the desired format when using the 'get_post_meta' function. This will be simpler through Toolset's own 'types_render_field' function, as it supports the 'format' attribute:
https://toolset.com/documentation/customizing-sites-using-php/functions/#date
I hope this helps and please let me know if you need further assistance.
regards,
Waqar
My issue is resolved now. Thank you!