Skip to content

Instantly share code, notes, and snippets.

@runezero
Created May 25, 2022 13:29
Show Gist options
  • Select an option

  • Save runezero/d5d2b7905efb5df869a6a3733c4cec0a to your computer and use it in GitHub Desktop.

Select an option

Save runezero/d5d2b7905efb5df869a6a3733c4cec0a to your computer and use it in GitHub Desktop.
[Set variable price range to from] Switch the variable product price range from the price range to a price from #woocommerce
add_filter( 'woocommerce_variable_sale_price_html', 'woodev_variable_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'woodev_variable_price_range', 10, 2 );
function dev_variable_price_range( $dev_price, $product ) {
$prefix = sprintf('%s: ', __('Vanaf', 'translate_domain'));
$dev_reg_min_price = $product->get_variation_regular_price( 'min', true );
$dev_min_sale_price = $product->get_variation_sale_price( 'min', true );
$dev_max_price = $product->get_variation_price( 'max', true );
$dev_min_price = $product->get_variation_price( 'min', true );
$dev_price = ( $dev_min_sale_price == $dev_reg_min_price ) ?
wc_price( $dev_reg_min_price ) :
'<del>' . wc_price( $dev_reg_min_price ) . '</del>' . '<ins>' . wc_price( $dev_min_sale_price ) . '</ins>';
return ( $dev_min_price == $dev_max_price ) ?
$dev_price :
sprintf('%s%s', $prefix, $dev_price);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment