Variable products are a product type that lets you give a set of variations on a product with control over prices, stock, image, and more for all variation. The variation price is usually appearing in the product summary area of the single product page. It displays once a visitor chooses the appropriate product options (named attributes). This covers things like size, color, etc.
One of these options is chosen, the variation price usually appears in the product summary area right below the product options selections.
As a beginner developer, it has been a little complex to Move woocommerce variation price anywhere of the web page. No many online solutions aren’t available on stackoverflow or online forums.
So in today’s, I will show some simple techniques, so that the variation of your single product page can be fitted to any div/element.
if( jQuery( ".variations_form select" ).length ){ // get json value from woocomerce from var product_attr = jQuery.parseJSON( $(".variations_form").attr("data-product_variations") ), obj_attr = ""; jQuery( ".variations_form select" ).on( "change", function () { // Create New Array by selecting variations jQuery( ".variations_form select" ).each(function( index ) { obj_attr[ $(this).attr("name") ] = $(this).val(); }); // Get Variations jQuery.each( product_attr, function( index, loop_value ) { if( JSON.stringify( obj_attr ) === JSON.stringify( loop_value.attributes ) ){ $('#update_here_your_id_or_class').html( loop_value.price_html ); } }); }); }
Let me know if this assists you! Alike, a share, anything at all to promote our content would is appreciated!
When working with WooCommerce variation, you may need to add WooCommerce Variation Swatches plugins in WordPress.
I would like to recommend you WooCommerce variation swatches pro. It is a variation swatches plugin that comes with incredible functions. This plugin allows you to add labels, images, and colors to give your shoppers the ultimate experience. the plugins will give your customers satisfaction and boost your sales with the most wonderful variation features.
Alan
Hi, where do I have to enter this code to make it work properly?
aThemeArt
Hi @alan
you can any js file above code. one more thing, make sure you have replaced
replace
thanks
Edoardo Guerini
Hi, i have test your code and nothing happen!
aThemeArt
HI
make sure you have chosen the right element id!
Thanks
Lavrendev
You have to define obj_attr as object.
Meaning:
obj_attr = {}
aThemeArt
Yes..