• Resolved Gal Baras

    (@galbaras)


    Besides using enhanced eCommerce, I want to trigger an event when a WooCommerce sale happens, using the amount (rounded to the next integer) as the value of the event.

    How do I do it with this plugin?

Viewing 1 replies (of 1 total)
  • Thread Starter Gal Baras

    (@galbaras)

    If anyone’s interested:

    
    add_action( 'woocommerce_thankyou', 'gbol_track_sale_event' );
    function gbol_track_sale_event( $order_id ) {
    	$order = wc_get_order( $order_id );
    
    	if ( $order->has_status( 'failed' ) ) {
    		return;
    	}
    	
    	$total = round( $order->get_total() );
    	if ( $total == 0 ) {
    		$total = '0';
    		$gateway = 'None';
    	} else {
    		$gateway = $order->get_payment_method_title();
    	}
    	echo "<script>ga( 'send', 'event', 'Rounded Sale', 'New Sale', '$gateway', $total );</script>";
    }
    
Viewing 1 replies (of 1 total)
  • The topic ‘How to trigger a sale event with order details’ is closed to new replies.