gravityflowwoocommerce_can_create_entry

The gravityflowwoocommerce_can_create_entry filter can be used to control if a new entry should be created after a WooCommerce Order is placed.

Parameters

$can_create boolean

The result to be overridden.

$form_id int

Form ID.

$order WC_Order

WC_Order object.

Example

The following example shows how to create new entries only when the order contains a certain product.

add_filter( 'gravityflowwoocommerce_can_create_entry', 'my_gravityflowwoocommerce_can_create_entry', 10, 3 );
function my_gravityflowwoocommerce_can_create_entry( $can_create, $form_id, $order ) {
	// Say the form id is 2.
	if ( $form_id == 2 && $can_create === true ) {
		// Disable entry creation.
		$can_create = false;
		$items = $order->get_items();
		foreach ( $items as $item ) {
			$product_id = $item['product_id'];
			// Say the product id you're looking for is 33.
			if ( $product_id === 33 ) {
				// Enable entry creation when the order contains the product.
				$can_create = true;
			}
		}
	}
	return $can_create;
}
The following example shows how to create new entries only when the order contains certain products.
add_filter( 'gravityflowwoocommerce_can_create_entry', 'my_gravityflowwoocommerce_can_create_entry', 10, 3 );
function my_gravityflowwoocommerce_can_create_entry( $can_create, $form_id, $order ) {
	// Say the form id is 2.
	if ( $form_id == 2 && $can_create === true ) {
		// Disable entry creation.
		$can_create = false;
		$items = $order->get_items();
		foreach ( $items as $item ) {
			$product_id = $item['product_id'];
			// Say the product ids you're looking for are 33, 44 and 55 .
			if ( in_array( $product_id, array( 33, 44, 55 ) ) ) {
				// Enable entry creation when the order contains one of these products.
				$can_create = true;
			}
		}
	}
	return $can_create;
}

Since

This filter was added in version 1.1.

Placement

This code should be placed in the functions.php file of your active theme.