Skip Navigation

[Resolved] Retrieve toolsed custom field value with PHP

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Seb Gates 10 months, 2 weeks ago.

Assisted by: Waqar.

Author
Posts
#2612705

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".

#2612837

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#2612899

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.