https://thewatersportscentre.com/product/ozone-wasp-v2-foil-wing-2021/
Here’s a link to the website in question with a variable product (with 2 attributes) as an example. You can see here the variations which are in stock trigger the price to change, where as out of stock (or hidden) variations simply shows default var product price “from £790”.
I actually have [“Hide out of stock items from the catalog” in woocommerce > settings > product > inventory] unchecked and i am using this code snippet below to hide the out of stock variations
————————
add_filter( 'woocommerce_variation_is_active', 'grey_out_variations_when_out_of_stock', 10, 2 );
function grey_out_variations_when_out_of_stock( $grey_out, $variation ) {
?>
<script type="text/javascript">
jQuery( document ).bind( 'woocommerce_update_variation_values', function() {
jQuery( '.variations select option' ).each( function( index, el ) {
var sold_out = '<?php _e( 'sold out', 'woocommerce' ); ?>';
var re = new RegExp( ' - ' + sold_out + '$' );
el = jQuery( el );
if ( el.is( ':disabled' ) ) {
if ( ! el.html().match( re ) ) el.html( el.html() + ' - ' + sold_out );
} else {
if ( el.html().match( re ) ) el.html( el.html().replace( re,'' ) );
}
} );
} );
</script>
<?php
if ( ! $variation->is_in_stock() )
return false;
return true;
}
————————
I am also using this code snippet below to replace the variable price range by the chosen variation price so that there is just 1 price at the top when selecting variations
————————
add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 );
function move_variations_single_price(){
global $product, $post;
if ( $product->is_type( 'variable' ) ) {
add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );
}
}
function replace_variation_single_price() {
?>
<style>
.woocommerce-variation-price {
display: none;
}
</style>
<script>
jQuery(document).ready(function($) {
var priceselector = '.product p.price';
var originalprice = $(priceselector).html();
$( document ).on('show_variation', function() {
$(priceselector).html($('.single_variation .woocommerce-variation-price').html());
});
$( document ).on('hide_variation', function() {
$(priceselector).html(originalprice);
});
});
</script>
<?php
}
————————
Hopefully this helps more with the scenario and i really appreciate your help!
-
This reply was modified 3 years, 4 months ago by Russell.