Created
March 6, 2023 11:18
-
-
Save wpserve/430c34449708a7dcd5b630839a05cdbc to your computer and use it in GitHub Desktop.
Price filter with included taxes
This file contains 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 | |
// If prices include taxes | |
add_filter( 'wpc_set_num_shift', 'flrt_set_num_shift', 10, 2 ); | |
function flrt_set_num_shift( $value, $entity_name ) { | |
if ( $entity_name === '_price' ) { | |
// Let's imagine that tax is 10% | |
// The final price will be | |
// $price_with_tax = $price + $price*0.1; | |
$value = $value + $value * 0.1; | |
} | |
return $value; | |
} | |
add_filter( 'wpc_unset_num_shift', 'flrt_unset_num_shift', 10, 2 ); | |
function flrt_unset_num_shift( $value, $entity_name ) { | |
if ( $entity_name === '_price' ) { | |
// $price_with_tax = x + x*0,1 | |
// $price_with_tax = 1.1x | |
// x = $price_with_tax/1.1 | |
$value = $value/1.1; | |
} | |
return $value; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment