wc_protected_product_add_to_cart

Prevent password protected products being added to the cart.

Description

wc_protected_product_add_to_cart( (bool) $passed, (int) $product_id ); 

Parameters (2)

0. $passed (bool)
The passed.
1. $product_id (int)
The product id.

Usage

  1. if ( !function_exists( 'wc_protected_product_add_to_cart' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-cart-functions.php'; 
  3.  
  4. // The passed. 
  5. $passed = true; 
  6.  
  7. // The product id. 
  8. $product_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_protected_product_add_to_cart($passed, $product_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-cart-functions.php  
  1. function wc_protected_product_add_to_cart( $passed, $product_id ) { 
  2. if ( post_password_required( $product_id ) ) { 
  3. $passed = false; 
  4. wc_add_notice( __( 'This product is protected and cannot be purchased.', woocommerce ), error ); 
  5. return $passed;