Which part should i change this snippet to work again
-
Hi,
One of the UX fail of WooCommerce is not to see the prices of variation if you don’t click to it.I was using following snippet to show prices of variations without needing clicking to variation first.
After updating WooCommerce 4, it isn’t functioning. (And my feedback form on Hotjar customer keep sending message ‘show prices’ for the variation products. They can’t see )
Which part should I update to make this snippet work again?
//Add prices to variations // add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' ); function display_price_in_variation_option_name( $term ) { global $wpdb, $product; if( isset( $product ) ) { $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" ); $term_slug = ( !empty( $result ) ) ? $result[0] : $term; $query = sprintf( "SELECT postmeta.post_id AS product_id FROM {$wpdb->prefix}postmeta postmeta LEFT JOIN {$wpdb->prefix}posts products ON ( products.id = postmeta.post_id ) WHERE postmeta.meta_key LIKE 'attribute_%%' AND postmeta.meta_value = '%s' AND products.post_parent = %d", $term_slug, $product->get_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] ); $itemPrice = strip_tags (wc_price( $_product->get_price() )); //this is where you can actually customize how the price is displayed return $term . ' ('. $itemPrice .')'; } } return $term; }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Which part should i change this snippet to work again’ is closed to new replies.