• Resolved xabdu

    (@xabdu)


    Hi,

    This is what my functions.php file looks like. I hid my site with ” ********* ”

    //Auto Complete Processing WooCommerce orders on Thankyou Page
    
    add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
    function custom_woocommerce_auto_complete_order( $order_id ) { 
        if ( ! $order_id ) {
            return;
        }
    
        $order = wc_get_order( $order_id );
        if ( $order->has_status('processing') ) {
            $order->update_status( 'completed' );
        }
       
    }
    
    // Redirect WooCommerce checkout page to ******************** after the payament
    add_action( 'woocommerce_thankyou', 'pfwp_redirect_woo_checkout');
    function pfwp_redirect_woo_checkout( $order_id ){
        $order = wc_get_order( $order_id );
        $url = 'https://*********/*********/*********/';
        if ( ! $order->has_status( 'failed' ) ) {
            wp_safe_redirect( $url );
            exit;
        }
    }

    And I want to add the Event snippet inside the Thank You for google ads.

    <!-- Event snippet for Purchase conversion page -->
    <script>
      gtag('event', 'conversion', {
          'send_to': 'AW-***********/********kDENy8vL4o',
          'value': 1.0,
          'currency': 'SAR',
          'transaction_id': ''
      });
    </script>
    <!-- End Event snippet for Purchase conversion page -->

    Because I am redirecting the thank you page to another page, the script will trigger? Or not?

    And how and where do I add the Event snippet at the functions.php because I have a lot of code that controls WooCommerce?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @xabdu

    This is a bit out of scope for us, but I noticed that you have asked it here too:

    https://stackoverflow.com/questions/71543236/how-to-add-google-ads-conversion-purchase-event-to-my-woocommerce-thank-you-page

    Have you tried the solution posted there? Changin the hook priority should do the job as mentioned there!

    All the best,

    Thread Starter xabdu

    (@xabdu)

    Hi,

    I don’t know where I should add the codes that the person gave me. And where I should paste the event snippet.

    Can you combine it with my functions.php as I wrote it above and include the new codes and the event snippet?

    Hi @xabdu!

    You can use the Code Snippets plugin for that. It allows you to easily add snippets to your site rather than pasting them in the functions.php or any other PHP file.

    Just copy the code from the article according to what you want to achieve; then, click Add New on the Code Snippets plugin, enter a title for the snippet for reference, paste the code, and you’re good to go.

    You can refer to this documentation for pointers.

    Since custom coding is outside our scope of support, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For additional assistance on this topic, we recommend getting in touch with one of the customization experts listed on the WooCommerce Customizations Page.

    Also, you can visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack, you could find help from the community of open-source developers for WooCommerce that hangs in there.

    Cheers!

    Seems we’ve not had additional inputs on this thread. Thus, we encourage you to make use of the above resources.

    I’ll go ahead and mark the thread as resolved but please feel free to create a new thread if you have further questions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add Google Ads conversion purchase event to my Thank you Page’ is closed to new replies.