cwcfp_category_in_cart_check
The cwcfp_category_in_cart_check
filter allows you to modify the default behavior when checking if a product from a particular category 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 a product from a given category is in the cart. False would mean that the plugin will behave as if a product from a given category is not in the cart.
The filter receives four attributes:
- $category_in_cart (bool): true if the product category is currently in the cart, false if it is not.
- $field (object): The conditional field's settings.
- $category_id (array): The category ids 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_category_in_cart_check', 'my_conditional_field_check', 10, 5 ); function my_conditional_field_check( $category_in_cart, $field, $category_id, $cart_contents ){ // Do your check return $category_in_cart; }