douyou7102 2017-03-21 19:02
浏览 49
已采纳

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

  • 写回答

1条回答 默认 最新

  • dongwen7730 2017-03-21 19:32
    关注

    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()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?