Description
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
Parameter | Type | Definition |
---|---|---|
$can_create | bool | The result to be overridden. |
$form_id | Integer | Form ID. |
$order | Order | WC_Order object. |
Examples
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;
}
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 can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?