Skip to content

Instantly share code, notes, and snippets.

@mrabro
Last active November 1, 2022 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrabro/b405ab9dfbe88baa2637d8df9f16e558 to your computer and use it in GitHub Desktop.
Save mrabro/b405ab9dfbe88baa2637d8df9f16e558 to your computer and use it in GitHub Desktop.
Woocommerce variable product, include price with attribute name in variation dropdown.
<?php
// For changing Option Name of variable product on Front end, including price with attribute name
add_filter( 'woocommerce_variation_option_name', function($option, $null, $attribute, $product){
if($product instanceof WC_Product_Variable){
$variations = $product->get_available_variations();
foreach ($variations as $key => $value) {
if(isset($value['attributes']['attribute_volume']) && isset($value['display_price']) && $value['attributes']['attribute_volume'] == $option){
$option = $value['attributes']['attribute_volume'].' - Rs.'.$value['display_price'].'/-';
}
}
}
return $option;
}, 11, 4);
@mrabro
Copy link
Author

mrabro commented Nov 1, 2022

Screen Shot 2022-11-01 at 1 16 09 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment