Home Forums Front-end Issues Display Custom Fields At Thank You WOOComerce Page


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,

    $fields = get_field_objects();
    if( $fields ): ?>

      <?php foreach( $fields as $field ): ?>

    • <?php echo $field[‘label’]; ?>: <?php echo $field[‘value’]; ?>
    • <?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

  • Hi @jarvis, just to say thank you for your answer. Very kind, you’ve helped me a lot. thanks man.

    To @vicmar: It’s easy to give a simple feedback to those who have invested their time in helping you. And please learn how to use code tags.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.