Skip to content

Instantly share code, notes, and snippets.

@thetwopct
Last active January 8, 2023 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thetwopct/7e1b3f0533d9232f4528e38057126eea to your computer and use it in GitHub Desktop.
Save thetwopct/7e1b3f0533d9232f4528e38057126eea to your computer and use it in GitHub Desktop.
Customisation of Tax Toggle for WooCommerce for compatibility with 99w Rentals Plugin
<?php
/**
* Customisation of Tax Toggle for WooCommerce for compatibility with 99w Rentals Plugin
*
* Based on Tax Toggle for WooCommerce 1.3.6
*
* Plugin: https://1.envato.market/taxtoggle
*
* @param string $price_display_override Rental price.
* @param string $product_price Full price.
* @param object $product Product.
* @return string
*/
function ttp_99w_rental_tax_change( $price_display_override, $product_price, $product ) {
// Remove popular currencies. If you use a different currency add the unicode to the array.
$price_display_override = str_replace( array( '&#36;', '&#8364;', '&#163;' ), '', $price_display_override );
// Remove rest of non-alpha numeric.
$price_display_override = preg_replace( '/[^0-9.]/', '', $price_display_override );
// setup custom text options.
$wc_incl = __( 'Incl.', 'wc-tax' );
$wc_excl = __( 'Excl.', 'wc-tax' );
$wc_zero = __( 'No Tax', 'wc-tax' );
$wc_from = __( 'From', 'wc-tax' );
$wc_rent_from = __( 'Rent from ', 'wc-tax' );
$wootax_text = get_option( 'wc_tax_text', 'VAT' );
// set default tax word if option is not set.
if ( '' === $wootax_text ) {
$wootax_text = __( 'VAT', 'wc-tax' );
}
$product_tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
$tax_amount = WC_Tax::calc_tax( $price_display_override, $product_tax_rates, false );
$price_inc_tax = $price_display_override + array_sum( $tax_amount );
return '<span class="amount product-tax-on product-tax" style="display:none;">' . $wc_rent_from . wc_price( $price_inc_tax ) . ' ' . $wc_incl . ' ' . $wootax_text . '</span><span class="amount product-tax-off product-tax">' . $wc_rent_from . wc_price( $price_display_override ) . ' ' . $wc_excl . ' ' . $wootax_text . '</span>';
}
add_filter( 'wcrp_rental_products_rental_price_html', 'ttp_99w_rental_tax_change', 3, 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment