Automattic\WooCommerce\Admin\API\Reports\Customers

DataStore::get_or_create_customer_from_order()public staticWC 1.0

Get or create a customer from a given order.

Method of the class: DataStore{}

Hooks from the method

Return

Int|true|false.

Usage

$result = DataStore::get_or_create_customer_from_order( $order );
$order(object) (required)
WC Order.

DataStore::get_or_create_customer_from_order() code WC 8.7.0

public static function get_or_create_customer_from_order( $order ) {
	if ( ! $order ) {
		return false;
	}

	global $wpdb;

	if ( ! is_a( $order, 'WC_Order' ) ) {
		return false;
	}

	$returning_customer_id = self::get_existing_customer_id_from_order( $order );

	if ( $returning_customer_id ) {
		return $returning_customer_id;
	}

	list($data, $format) = self::get_customer_order_data_and_format( $order );

	$result      = $wpdb->insert( self::get_db_table_name(), $data, $format );
	$customer_id = $wpdb->insert_id;

	/**
	 * Fires when a new report customer is created.
	 *
	 * @param int $customer_id Customer ID.
	 * @since 4.0.0
	 */
	do_action( 'woocommerce_analytics_new_customer', $customer_id );

	return $result ? $customer_id : false;
}