Wordpress + Woocommerce: hide unavailable variations when there are 2 attributes

送分小仙女□ 提交于 2019-12-10 15:44:40

问题


I have a variable product in WordPress + WooCommerce and it has 2 attributes: color and size.

I'd like that when I select one of these 2 attributes, the unavailable variations with the second attribute will be automatically hidden (or unselectable) from the attribute select menu.

Is it possible? How can I achieve that?

I haven't found any plugin that can do that. I'm trying to figure out what part of code to edit, but it's quite a difficult task...


回答1:


I ran into your (old) question as i had it too. This is a working solution. Change 'return 10' to a number higher than your total amount of variations.

Add it to your function.php file:

function custom_wc_ajax_variation_threshold( $qty, $product ) {
    return 10;
}

add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );


来源:https://stackoverflow.com/questions/23239003/wordpress-woocommerce-hide-unavailable-variations-when-there-are-2-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!