Prices of variations in pull-down menus, it works, but not on bundled products
-
I’ve got code to display prices in pull-down menus for variations of products on a site and it’s working great except for when variations are bundled products.
What happens here is that in the list of variations, only one bundled product seems to get a price and it’s surrounded with a <span> tag. Could anyone be able to tell me from the code below why it wouldn’t be working for bundled products?
Here is an example where the code does work on single product variations.
Here is an example page where it’s not working correctly on variations made of bundled products.
And here is the code I’m using. I’m not very versed at this level of PHP so if someone can point out what I need to add or modify, I’d be so grateful.
<?php //show price next to variations in woocommerce add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' ); function display_price_in_variation_option_name( $term ) { global $wpdb, $product; $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" ); $term_slug = ( !empty( $result ) ) ? $result[0] : $term; $query = "SELECT postmeta.post_id AS product_id FROM {$wpdb->prefix}postmeta AS postmeta LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id ) WHERE postmeta.meta_key LIKE 'attribute_%' AND postmeta.meta_value = '$term_slug' AND products.post_parent = $product->id"; $variation_id = $wpdb->get_col( $query ); $parent = wp_get_post_parent_id( $variation_id[0] ); if ( $parent > 0 ) { $_product = new WC_Product_Variation( $variation_id[0] ); return $term . ' (' . woocommerce_price( $_product->get_price() ) . ')'; } return $term; } ?>
- The topic ‘Prices of variations in pull-down menus, it works, but not on bundled products’ is closed to new replies.