How did you hear about us – radio options in Thank You Page Woocommerce

It’s essential to comprehend how buyers find your WooCommerce store in order to customize your marketing tactics. The “WooCommerce Thank You Page Awareness Form” snippet provides a smooth method of gathering this important data. Right after a customer completes a purchase, you can learn more about their journey by including a straightforward feedback form on the thank you page.

The Awareness Feedback Form’s advantages

This sample incorporates a feedback form that inquires about clients’ sources of information about your store. Specific data points are provided via options like “Google Search,” “Social Media,” and “Through a friend” that can help you focus your marketing efforts. Higher response rates and more accurate statistics are guaranteed when this information is gathered as soon as the purchase is made.

Using Ajax to Streamline Data Collection

The form offers a seamless user experience by using Ajax to communicate responses without requiring a page reload. After the client makes a selection, the server receives their feedback, which is then noted in the order notes. This guarantees that the data is effectively collected and stored for further analysis in addition to making the procedure user-friendly.

Owners of WooCommerce stores can enhance their understanding of their customer acquisition channels and tailor their marketing tactics by putting this feedback form into practice.

    
/* * Snippet Name: WooCommerce Thank You Page awareness form * Snippet Author: ecommercehints.com */ add_action( 'woocommerce_thankyou', 'ecommercehints_awareness_feedback_form', 20 ); function ecommercehints_awareness_feedback_form( $order_id ) { echo '<h2>How Did You Hear About Us?</h2> <form id="awareness_feedback_form"> <label><input type="radio" name="awareness" value="Google Search"> Google Search</label><br> <label><input type="radio" name="awareness" value="Social Media"> Social Media</label><br> <label><input type="radio" name="awareness" value="Through a friend"> Through a friend</label> <input type="hidden" name="action" value="collect_feedback" /> <input type="hidden" name="order_id" value="' . $order_id . '" /> ' . wp_nonce_field( 'thankyou'.$order_id, 'thankyou_nonce', true, false ) . ' </form>'; } add_action( 'wp_footer', 'ecommercehints_thank_you_ajax_message' ); function ecommercehints_thank_you_ajax_message(){ if( !is_wc_endpoint_url( 'order-received' ) ) return; echo "<script> jQuery( function( $ ) { $('input[type=radio][name=awareness]').change(function() { $.ajax({ url: '" . admin_url('admin-ajax.php') . "', type: 'POST', data: $('#awareness_feedback_form').serialize(), beforeSend : function( xhr ){ $('#awareness_feedback_form').html('Nice one, thanks for your feedback!'); }, success : function( data ){ console.log( data ); } }); }); }); </script>"; } add_action( 'wp_ajax_collect_feedback', 'ecommercehints_thank_you_ajax' ); add_action( 'wp_ajax_nopriv_collect_feedback', 'ecommercehints_thank_you_ajax' ); function ecommercehints_thank_you_ajax(){ check_ajax_referer( 'thankyou'.$_POST['order_id'], 'thankyou_nonce' ); if( $order = wc_get_order( $_POST['order_id'] ) ) { $store_name = get_bloginfo('name'); $note = $order->get_formatted_billing_full_name() . ' heard about ' . $store_name . ' through: ' .$_POST['awareness'] . '.'; $order->add_order_note( $note, 0, true ); } die(); }

Leave a Reply

Your email address will not be published. Required fields are marked *