Variable product selectors: Getting the live selected values

后端 未结 2 617
死守一世寂寞
死守一世寂寞 2020-12-16 06:59

In WooCommerce use the code below to add a custom label after product prices in simple and variables products:

add_filter(\'woocommerce_variation_price_html\         


        
2条回答
  •  心在旅途
    2020-12-16 07:49

    The only way to get this working is to use Javascript / jQuery, but it's complicated as WooCommerce is already running some Javascript / Ajax code on it.

    First, Is not possible to detect the selected customer choice on the selectors as WooCommerce remove "selected" attribute from html tags.

    Once customer have make a complete selection (so choosed one variation from this variable product), Woocommerce add the corresponding variation ID value in a hidden html field and display the corresponding price.

    Our PHP code pass to javascript an array of the variations IDs for this variable product, with the corresponding value of the "quantity" attribute for each of them.

    Then we can use the "on blur" javascript event on the

    提交评论

提交回复
热议问题