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;
	if ( $excluded_attribute === $attribute['id'] ) {
		return 0;
	}
	return $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;
	if ( $max_attributes < count( $product->get_attributes() ) ) {
		return 'no';
	}
	return $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;
	if ( $excluded_product === $product->get_id() ) {
		return false;
	}
	return $included;
}

Leave a Reply

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