• Resolved rodcul

    (@rodcul)


    I would love to store the gclid parameter similar to the abandoned carts similar to how this code snippet I found on StackOverflow does it for orders.

    Any suggestions? Thanks!

    // Adding Google Adwords gclid parameter to Woocommerce Database
    add_action( 'init', 'gclid_session' );
    function gclid_session () {
        // Early initialize customer session
        if ( isset(WC()->session) && ! WC()->session->has_session() ) {
            WC()->session->set_customer_session_cookie( true );
        }
        if ( isset( $_GET['gclid'] ) ) {
            $gclid_ide = isset( $_GET['gclid'] )  ? esc_attr( $_GET['gclid'] )  : '';
            // Set the session data
            WC()->session->set( 'gclid_id', $gclid_ide );
        }
    }
    
    // Save session data as order meta data
    add_action( 'woocommerce_checkout_create_order', 'set_order_gclid_meta' );
    function set_order_gclid_meta( $order ) {
        $gclid_ide = WC()->session->get( 'gclid_id' ); // Get custom data from session
        if ( isset($gclid_ide) ) {
            $order->update_meta_data( '_gclid', $gclid_ide );
        }    
        WC()->session->__unset( 'gclid_id' ); // Remove session variable
    }
    
    // Show this session variables in new order email for admin and in woocommerce order page
    // add_action( 'woocommerce_email_after_order_table', 'show_gclid_data', 20 );
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'show_gclid_data' );
    function show_gclid_data( $order ) {
        if ( $id_gclid = $order->get_meta( '_gclid' ) )
            echo '<p><strong>gclid :</strong> ' . $id_gclid . '</p>';
    }
    • This topic was modified 1 year, 6 months ago by rodcul.

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Sravan Bhaskaravajjula

    (@bhshravankumar)

    Hello @rodcul,

    I am not sure if this is possible with the cart abandonment plugin, please share your use case of using this with the cart abandonment.

    By the way, you can add custom UTM parameters from the plugin’s settings, please refer to this screenshot.

    Looking forward to hearing from you.

    Plugin Support Sravan Bhaskaravajjula

    (@bhshravankumar)

    Hello @rodcul,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.
    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Save Google Ads GCLID value to Abandoned Carts’ is closed to new replies.