Filter gets price of main product instead of the price of the product in block
-
Hi,
As soon as i apply the following code, it displays the price of the main product instead of the product from woocommerce blocks. If this is not the place, please let me know.
add_filter( 'woocommerce_get_price_html', 'pm_price_formatting', 99, 2 ); function pm_price_formatting ( $price, $product ){ global $product; if ( $product ) { $currency = esc_attr( get_woocommerce_currency( ) ); // Get the currency code. $price_excl_tax = number_format (wc_get_price_excluding_tax( $product ), 2); // price without VAT $price_incl_tax = number_format (wc_get_price_including_tax( $product ), 2); // price with VAT $int = wc_get_price_decimals(); $price = '<span class="price-without-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) .$price_excl_tax.' (Exc. BTW)'.'</span>'.'<br>'.'<span class="price-with-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) . $price_incl_tax.' (Inc. BTW)'.'</span>'; } return $price; } add_filter( 'aws_search_pre_filter_products', 'my_aws_search_pre_filter_products' ); function my_aws_search_pre_filter_products( $products_array ) { if ( $products_array && ! empty( $products_array ) ) { foreach ( $products_array as $key => $product ) { $product_obj = wc_get_product( $product['id'] ); if ( $product_obj ) { $currency = esc_attr( get_woocommerce_currency( ) ); // Get the currency code. $price_excl_tax = number_format (wc_get_price_excluding_tax( $product_obj ), 2); // price without VAT $price_incl_tax = number_format (wc_get_price_including_tax( $product_obj ), 2); // price with VAT $int = wc_get_price_decimals(); $price = '<span class="price-without-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) .$price_excl_tax.' (Exc. BTW)'.'</span>'.'<br>'.'<span class="price-with-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) . $price_incl_tax.' (Inc. BTW)'.'</span>'; $products_array[$key]['price'] = $price; } } } return $products_array; }
The Code adds an extra price under the normal which displays VAT or BTW here. Is there a way to get the actual price of the product displayed in the block instead of the price of the product where the block is added.
Many thanks,
Auke Hendriks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Filter gets price of main product instead of the price of the product in block’ is closed to new replies.