Woocommerce:如果产品的可用尺寸少于两种,则从导入中排除产品

Some products have multiple sizes, for example: "size: S, M, L, XL"

We have the following code in our Custom Code plugin to separate and identify the different sizes:

add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_size_attribute2',     20, 6 );
function mycode_add_size_attribute2( $value, $attribute, $post, $product,  $set, $action ) {
    if ( $attribute == 'pa_maat' ) {
        if ( isset( $product['size'] ) ) {
            $value = mycode_get_size2( $product['size'] );
        }
    }

    return $value;
}

Is it possible to only import products that have more than three sizes?

(for example: product with sizes “S, M, XL” will be in the shop, product with sizes “S, M” will not be in the shop)

Thanks,

Solomon

If $value is being returned as an array or countable object, you can use the count() function such as

if (count($value) > 3){
//custom code here
}

More information: Count()