cwcfp_product_in_cart_check

The cwcfp_product_in_cart_check filter allows you to modify the default behavior when checking if a product is in the cart.

The function passed to this filter should return either true or false. True would mean that the plugin will behave as if the product is in the cart. False would mean that the plugin will behave as if the product is not in the cart.

The filter receives 5 attributes:

  • $product_in_cart (bool): true if the product is currently in the cart, false if it is not.
  • $field (object): The conditional field's settings.
  • $product_ids (array): The product ids that should be in the cart based on the field's settings in order for this field to be displayed.
  • $variations (array/false): The product variations that should be in the cart based on the field's settings in order for this field to be displayed.
  • $cart_contents (object): The current contents of the cart that can be checked.

If you always want a field to be displayed on the checkout page, you can use the filter like this:

	add_filter( 'cwcfp_product_in_cart_check', '__return_true', 10, 5 );

If you want to test several conditions before showing the field on the checkout page, you can also do that.

	add_filter( 'cwcfp_product_in_cart_check', 'my_conditional_field_check', 10, 5 );
	function my_conditional_field_check( $product_in_cart, $field, $product_ids, $variations, $cart_contents ){
		// Do your check
		return $product_in_cart;
	}