Lead Gen & CRM
How can we help you?
Search our help articles, video tutorials, and quickstart guides

You've got this. You've got us. Search our Knowledge Base to quickly find answers to your questions.

Integrating Shopping Cart with WooCommerce

Article: 000050395
Updated: July 18, 2024

Connect your Lead Gen & CRM shopping cart with your WooCommerce store

Integrating with Lead Gen & CRM's shopping cart allows you to automatically record web transactions from your online store and attribute those sales to Lead Gen & CRM's leads and campaigns. This enables you to measure your end-to-end marketing ROI for eCommerce based businesses directly in Lead Gen & CRM. This article will detail how to integrate your shopping cart with WooCommerce.

 
 
Users:
Administrators 
Company Managers  
Marketing Managers  
Sales Managers  
Salespersons  
Jr. Salespersons  


Integrating Shopping Carts with WooCommerce

In order to integrate Lead Gen & CRM with WooCommerce, you need to have administrator access to your Wordpress account. In addition, you will need administrator access to Lead Gen & CRM.

To set up and integrate a shopping cart, do the following:

  1. Within Wordpress, Click Editor, located under Appearance in the left menu.
  2. Open the functions.php file in the right menu.
  3. Add the code snippet located below this procedure to the bottom of your functions.php file. 
  4. Locate 'Store Name' in the code.
  5. Change this to be the name of your online store. 
  6. Save the functions.php file.


 

To test that the integration is working properly, create a product in your store that is sold for $0.00 and purchase that product. Once purchased, that transaction should show up in Lead Gen & CRM's shopping cart.

Important: While Shopping Cart Abandonment was created to work with various platforms, the implementation and ease of use will vary by platform. Usually, we do not support abandonment for WooCommerce without an additional plugin. Lead Gen & CRM recommends having a developer handle abandonment implementation. Pay close attention to the code that you add to functions.php. If you add incorrect code, you may be locked out of your Wordpress account.

Note: If the lead's email, first name, and last name are passed in the setTransaction call, it will also establish tracking on the lead (and create the lead if they do not exist in Lead Gen & CRM).



Code Snippet for Functions.PHP File

The following is the supplied code snippet for use with Step 7 of the above procedure:

/* SharpSpring WooCommerce integration 
 * This code will push completed orders and new leads to SharpSpring, but this integration does not support abandoned carts
*/
function my_custom_tracking( $order_id ) {

	//Get the order from WooCommerce
	$order = wc_get_order( $order_id );
	$billing = $order->get_address('billing');
	?>
	
	<script type='text/javascript'>
	// SharpSpring setTransaction for WooCommerce
	_ss.push(['_setTransaction', {
		   'transactionID': '<?php echo $order->get_order_number(); ?>',
		   'storeName': 'Store Name',
			'total': 	'<?php echo $order->get_total(); ?>',
			'tax': 		'<?php echo $order->get_total_tax(); ?>',
			'shipping': '<?php echo $order->get_total_shipping(); ?>',
			'city': 	'<?php echo $billing['city']; ?>',
			'state':	'<?php echo $billing['state']; ?>',
			'zipcode': 	'<?php echo $billing['postcode']; ?>',
			'country': 	'<?php echo $billing['country']; ?>',
			
	        'firstName' : 	'<?php echo $billing['first_name']; ?>', // optional parameter
	        'lastName' : 	'<?php echo $billing['last_name']; ?>', // optional parameter
	        'emailAddress' :'<?php echo $billing['email']; ?>' // optional parameter
		}]);

	<?php 
	//Get and loop through the items in the order
	$order_item = $order->get_items();
	foreach( $order_item as $product ) {

		$product_sku_array = new WC_Product($product['product_id']);
		$product_sku = $product_sku_array->get_sku();
		?>
		
		//SharpSpring addTransactionItem for WooCommerce
		_ss.push(['_addTransactionItem', {
			'transactionID':'<?php echo $order->get_order_number(); ?>',
			'itemCode': 	'<?php echo $product_sku; ?>',
			'productName': 	'<?php echo $product['name']; ?>',
			'category': 	'General',
			'price': 		'<?php echo $product['line_total']; ?>',
			'quantity': 	'<?php echo $product['qty']; ?>'
		}]);
		<?php 
	}
		?>
	
	//SharpSpring completeTransaction after all items have been added to the transaction
	_ss.push(['_completeTransaction', { 
		'transactionID': '<?php echo $order->get_order_number(); ?>'
	}]);
	</script>
	<?php
}

add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
/* End SharpSpring WooCommerce integration */
 


Did this article answer your question?


Constant Contact Logo

Copyright © 2025 · All Rights Reserved · Constant Contact · Privacy Center