get price from varation selected woocommerce code example

Example: display only price from selected variable woocommerce

add_action('woocommerce_before_add_to_cart_form', 'selected_variation_price_replace_variable_price_range');
function selected_variation_price_replace_variable_price_range(){
    global $product;

    if( $product->is_type('variable') ):
    ?><style> .woocommerce-variation-price {display:none;} </style>
    <script>
    jQuery(function($) {
        var p = 'p.price';

        $('form.cart').on('show_variation', function( event, data ) {
            $(p).html(data.price_html);
        }).on('hide_variation', function( event ) {
            $(p).html($(a).html());
        });
    });
    </script>
    <?php
    endif;
}

Tags:

Misc Example