Last active
November 1, 2022 10:05
-
-
Save mrabro/b405ab9dfbe88baa2637d8df9f16e558 to your computer and use it in GitHub Desktop.
Woocommerce variable product, include price with attribute name in variation dropdown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Author
mrabro
commented
Nov 1, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment