Categories
WooCommerce Extensions

Default Attributes for WooCommerce

How to exclude some attribute from the stock-based default attributes calculation?
Update the attribute id:

add_filter( 'daw_max_variations', 'exclude_attribute', 10, 2 );
function exclude_attribute( $max_variations, $attribute ) {
	$excluded_attribute = 25;
	return $excluded_attribute === $attribute['id'] ? 0 : $max_variations;
}

How to apply the first attribute option only on products with less than certain amount of attributes?
Update the amount of attributes:

add_filter( 'first_attribute_checkbox', 'daw_first_attribute_restrict_products', 10, 2 );
function daw_first_attribute_restrict_products( $first_attribute_checkbox, $product ) {
	$max_attributes = 3;
	return $max_attributes < count( $product->get_attributes() ) ? 'no' : $first_attribute_checkbox;
}

How to exclude product from all the default attributes calculations?
Update the product id:

add_filter( 'daw_include_product', 'exclude_product', 10, 2 );
function exclude_product( $included, $product ) {
	$excluded_product = 71;
	return $excluded_product === $product->get_id() ? false : $included;
}

Leave a Reply

Your email address will not be published. Required fields are marked *