• Hi there,

    i am trying to save custom client data from input fields for every order and put out a custom link with that infos on thank you page.

    I thought i could achieve it with saving the extra client data into a custom database table and reading that data into the thank you page and also saving this into the users profile (orders).

    Is there any chance doing it without extra plugins or do i need them?

    I would like to use the most easy way.

    Thanks in advance!

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Marc Lacroix

    (@marcusig)

    Hi there,

    You could do it, but it won’t be a simple task.

    You’ll need to:

    • When the Add to cart button is clicked, get the text information – for this you could probably use the javascript hook wp.hooks.doAction( 'PC.fe.add_to_cart.before', this );
    • Add this information to the cart form, in order for it to be submitted
    • In PHP, add the submitted text to the cart data (probably using the filter woocommerce_add_cart_item_data)

    Here’s an example of the JS hook you could use:

    // hook triggered when pressing the Add to cart button
    wp.hooks.addAction( 'PC.fe.add_to_cart.before', 'your_namespace', function( view ) { 
        // Get the add to cart form, which is stored in the view
        var $cart_form = view.$cart;
        // now you can append the data to the form.
    } );

    If you’re not familiar with the JS hooks, you can take a look at this starter plugin, which enqueues all the required scripts to work with the configurator: https://github.com/marcusig/pc-custom-code-bootstrap

    Marc

    Thread Starter jollock

    (@jollock)

    Hi Marc,

    thanks for your quick reply!

    Could you please give me another example on how to append data to the form?

    Thanks

    JD

    Plugin Contributor Marc Lacroix

    (@marcusig)

    You can try something like this:

    jQuery( '.mkl_pc_layers .custom-html.active textarea#heading' ).clone().appendTo( $cart_form );

    This should clone the textarea and add it to the form element.
    Note that you currently do not have a name attribute on your textareas, so their values might not be sent with the form data.

    Thread Starter jollock

    (@jollock)

    Hi Marc,

    thank you for your reply.

    I added the names for the textareas and got it working with your code – the only thing that’s not working is the output on the thank you page.

    I added the following code to my thank-you.php

    if ( $heading  = $order->get_meta('heading') ) {
      echo '<p>'. __("Heading") . ': ' . $heading . '</p>';
    }
    if ( $body = $order->get_meta('bodytext') ) {
      echo '<p>'. __("Body") . ': ' . $body . '</p>';
    }

    Unfortunately there is no output for that.

    I also tried to find the fields in the complete order with the following code:

    <?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>

    Nothing to find in this result, too.

    Do you see anything i’m doing wrong?

    Thanks in advance!

    Thread Starter jollock

    (@jollock)

    Hi Marc,

    i know, you have got a lot to do, but could you give me a hint on this? Or could you relate me to someone who can help me?

    Many thanks

    JD

    Plugin Contributor Marc Lacroix

    (@marcusig)

    Hi JD,

    It’s difficult to say what’s wrong without seeing the full code. Feel free to send it via this form if you’d rather not share it publicly: https://wc-product-configurator.com/contact

    Marc

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to save custom entries to an order and put out a custom link on thanks page’ is closed to new replies.