Home › Forums › Front-end Issues › Display fields on order-pay page
Hello,
I created a custom fields group to be displayed on Order pages. I’d like these custom fields to be displayed on the checkout page (WooC Pay page or pay-order) so that the customer can view the details and do her/his checkout.
https://drive.google.com/file/d/1UIsAYH3rODa-hPgULClMzAgZogeD9PDv/view?usp=sharing
Added a code block on form-pay.php to display my tour_start_date, as an example, however, it failed:
$tour_star_date = get_field( ‘tour_start_date’, $item->get_product_id() );
echo ‘<p>’ . $tour_star_date . ‘</p>’;
How can I display them on these pages, could you please help or guide me?
Thank you.
you need to use the order ID here, not the product ID
$tour_star_date = get_field( ‘tour_start_date’, $item->get_product_id() );
Hi John,
Thank you so much for your reply. But unfortunately it doesn’t work 🙁
https://drive.google.com/file/d/1YJrxKaEKjtQ0pJOxnG_0n33H6TgVKczg/view?usp=sharing
Did I miss something?
Here are all the screenshots:
https://drive.google.com/drive/folders/1XfojstMOTl_nCTYLqeGpvW3bDFxQ9B3C?usp=sharing
I honestly don’t know the answer. This is a WC thing. You are displaying the order page, the fields are saved against the “order” post. You need to supply the ID of that order post. So what you need to do is look into the WC documentation on how to get the ID of the order being shown.
Hi John!
Thank you so much for your feedback.
This worked as expected:
$acf_field_name = get_field('acf_field_name', $item->get_order_id());
Hi John,
Thank you so much for your kind reply, but unfortunately it doesn’t work.
Here’s my final code block:
$tour_start_date = get_field(‘tour_start_date’, $item->get_product_id());
if ($tour_start_date) {
echo ‘<p>’ . esc_html($tour_start_date) . ‘</p>’;
}
https://drive.google.com/file/d/1YNShRXEoQQ4ACnRHBE8rYcXhOf0kdcHx/view?usp=sharing
https://drive.google.com/file/d/1YJMmjoqz6p0vIorrQFbWTEq3Uzjnz2Br/view?usp=sharing
https://drive.google.com/file/d/1YKIUFwV7x-bhcf041aL5vZZ6HnPcqWQX/view?usp=sharing
https://drive.google.com/file/d/1YJrxKaEKjtQ0pJOxnG_0n33H6TgVKczg/view?usp=sharing
Did I miss something?
Hi John,
Thank you so much for your kind reply, but unfortunately it doesn’t work.
Here’s my final code block:
$tour_start_date = get_field(‘tour_start_date’, $item->get_product_id());
if ($tour_start_date) {
echo ‘<p>’ . esc_html($tour_start_date) . ‘</p>’;
}
https://drive.google.com/file/d/1YNShRXEoQQ4ACnRHBE8rYcXhOf0kdcHx/view?usp=sharing
https://drive.google.com/file/d/1YJMmjoqz6p0vIorrQFbWTEq3Uzjnz2Br/view?usp=sharing
Did I miss something?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.