Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- global $product;
- $variation_ids = array();
- if( $product->is_type('variable') ){
- $default_attributes = $product->get_default_attributes();
- foreach($product->get_available_variations() as $variation_values ){
- foreach($variation_values['attributes'] as $key => $attribute_value ){
- $attribute_name = str_replace( 'attribute_', '', $key );
- if( $attribute_name == 'pa_color'){
- $default_value = $product->get_variation_default_attribute($attribute_name);
- if( $default_value == $attribute_value ){
- // We set all related variation IDs in an array
- $variation_ids[] = $variation_values['variation_id'];
- }
- }
- }
- }
- if( count( $variation_ids ) > 0 ){
- // Iterating through each variation ID
- foreach( $variation_ids as $variation_id ){
- // Get the "default" WC_Product_Variation object
- $variation = wc_get_product($variation_id);
- // Get variation attribute values
- $variation_attributte = $variation->get_variation_attributes();
- // Raw output variation attribute values
- echo '<pre>'; print_r($variation_attributte); echo '</pre>';
- // Get the active price
- $price = $variation->get_price();
- // Output price
- echo '<p>Price: ' . $price . '</p>';
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment