wc_protected_product_add_to_cart( bool $passed, int $product_id )

Prevent password protected products being added to the cart.


Description Description


Parameters Parameters

$passed

(Required) Validation.

$product_id

(Required) Product ID.


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/wc-cart-functions.php

function wc_protected_product_add_to_cart( $passed, $product_id ) {
	if ( post_password_required( $product_id ) ) {
		$passed = false;
		wc_add_notice( __( 'This product is protected and cannot be purchased.', 'woocommerce' ), 'error' );
	}
	return $passed;
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.