Created
December 5, 2024 11:20
-
-
Save kartikparmar/d694baca93fa9b4d6377a08a0dc71f05 to your computer and use it in GitHub Desktop.
show booking price with tax information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function bkap_show_booking_price_with_tax( $wp_send_json, $product_id ) { | |
if ( 'yes' !== get_option( 'woocommerce_calc_taxes' ) ) { | |
return $wp_send_json; | |
} | |
$product_obj = wc_get_product( $product_id ); | |
$total_price = $wp_send_json['total_price_calculated']; | |
$tax_rates = WC_Tax::get_rates( $product_obj->get_tax_class() ); | |
if ( wc_prices_include_tax() ) { | |
$taxes = WC_Tax::calc_inclusive_tax( $total_price, $tax_rates ); | |
$included_tax = array_sum( $taxes ); | |
if ( $included_tax > 0 ) { | |
$display_price = $wp_send_json['bkap_price']; | |
$display_price .= ' <small>(' . sprintf( __( 'includes %s tax', 'woocommerce'), wc_price( $included_tax ) ) . ')</small>'; | |
$wp_send_json['bkap_price'] = $display_price; | |
} | |
} else { | |
$taxes = WC_Tax::calc_exclusive_tax( $total_price, $tax_rates ); | |
$tax_amount = array_sum( $taxes ); | |
if ( $tax_amount > 0 ) { | |
$display_price = $wp_send_json['bkap_price']; | |
$display_price .= ' <small>(' . sprintf( __( 'plus %s tax', 'woocommerce' ), wc_price( $tax_amount ) ) . ')</small>'; | |
$wp_send_json['bkap_price'] = $display_price; | |
} | |
} | |
return $wp_send_json; | |
} | |
add_filter( 'bkap_final_price_json_data', 'bkap_show_booking_price_with_tax', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment