Home › Forums › Front-end Issues › Display Custom Fields At Thank You WOOComerce Page
I need obtain the content custom fields. I add custom fields at WOOComerce Billing Form. I need obtain the field values to use within custom SQL procedure. I test diferents example codes but not functionally. I add the code in functions PHP on action woocommerce_thankyou
add_action(‘woocommerce_thankyou’, ‘action_woocommerce_before_checkout_form’);
The code is:
What it’s wrong (include different test code):
echo the_field(‘Usuario Web’);
echo the_field(‘billing_wooccm11’);
echo the_field(‘Provincia’);
echo the_field(‘billing_state’);
$variable2 = get_field(‘billing_wooccm11’);
echo ‘-‘ . $variable2 . ‘<br />’;
I test this code, when i visit the web have problem on PHP FUNCTIONS and don’t load,
<?php
$fields = get_field_objects();
if( $fields ): ?>
<?php endforeach; ?>
<?php endif; ?>
Hi @vicmar
If you’ve added custom fields to the billing form, this information is store against the order ID.
So on the thank you page, you need to access the order ID, then you should be able to access your custom field data.
For example:
$variable2 = get_field(‘billing_wooccm11’,$order_id);
I also believe this line is wrong:
add_action(‘woocommerce_thankyou’, ‘action_woocommerce_before_checkout_form’);
You’re trying to use a hook for the thank you page but mixed with an action on the checkout page (I may be wrong here!)
I think this is the correct hook:
function action_woocommerce_thankyou( $order_get_id ) {
// your code goes here
};
add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1 );
Or you could copy the thank-you.php file to your theme and add the code directly – obviously you need to still
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.