Is “woocommerce_price( $_product->get_price() )” depreciated?
-
I’ve been trying to add some code to display a variation’s price in the WooCommerce variation popup menu.
The suggested code (which is old) uses
'woocommerce_price( $_product->get_price() )"
. This outputs the price but also displays all the HTML code as well. Looking at the WC documentation this call isn’t mentioned anymore. Is this no longer supported?Here is the code in full, in case anyone is interested
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; }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Is “woocommerce_price( $_product->get_price() )” depreciated?’ is closed to new replies.