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', 'daw_exclude_attribute', 10, 2 );
function daw_exclude_attribute( $max_variations, $attribute ) {
	$excluded_attribute = 25;
	return $excluded_attribute === $attribute['id'] ? 0 : $max_variations;
}

How to set the plugin’s cache expiration time?
Update the number of seconds (1 means 1 second- suitable for testing, 3600 means hour- suitable for production):

add_filter( 'daw_transient_expiration', 'daw_disable_transients' );
function daw_disable_transients() {
	return '1';
}

How to apply the defaults on all the pages and not just the single product page?

add_filter( 'daw_defaults_enabled', '__return_true' );

How to force in-stock default variation (BETA)?

add_filter( 'daw_product_get_default_attributes', 'daw_product_force_default_attributes', 999, 2 );
function daw_product_force_default_attributes( $default_attributes, $product ) {
	foreach ( $product->get_available_variations() as $variation ) {
		if ( $variation['is_in_stock'] || $variation['backorders_allowed'] ) {
			foreach ( $variation['attributes'] as $key => $value ) {
				$default_attributes[ str_replace( 'attribute_', '', $key ) ] = $value;
			}
			break;
		}
	}
	return $default_attributes;
}

Leave a comment

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