Custom Functions

Here’s a quick example of how to use a Workflows with a Custom Function action to create an abandon cart log.

1. Create a Workflow

Screen-Shot-2015-04-29-at-10.22.15-pm

 

2. Create a function in your themes functions.php file

		/**
 * Abandoned Cart Log
 *
 * @param $workflow WC_Workflow
 * @param $log WC_Workflows_Log
 */
function my_wc_workflows_action_log_abandoned_carts( $workflow, $log )
{
	$cart = $workflow->get_data_item('cart');
	$user = $workflow->get_data_item('user');

	// The get_data_item method will validate data item or return false
	if ( ! $cart || ! $user ) return;

	$log = get_user_meta( $user->ID, 'abandoned_carts_log', true );

	if ( ! $log )
		$log = array();

	$log[] = array(
		'cart' => $cart,
		'date' => current_time( 'mysql', true )
	);

	update_user_meta( $user->ID, 'abandoned_carts_log', $log );
}