Created
July 14, 2017 19:15
-
-
Save greenhornet79/ba7432e460299603f2bab8511ba0826a to your computer and use it in GitHub Desktop.
add basic VAT abilities to Leaky Paywall
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
| add_action( 'leaky_paywall_before_registration_form', 'omg_show_vat_on_subscription_details' ); | |
| function omg_show_vat_on_subscription_details( $level ) { | |
| $vat_price = omg_calculate_vat_total( $level['price'] ); | |
| echo '<p><strong>With VAT Tax: </strong> ' . leaky_paywall_get_current_currency_symbol() . $vat_price . '</p>'; | |
| } | |
| add_filter( 'leaky_paywall_subscription_data', 'omg_add_vat_tax' ); | |
| function omg_add_vat_tax( $subscription_data ) { | |
| $amount = $subscription_data['amount']; | |
| $subscription_data['amount'] = omg_calculate_vat_total( $amount ); | |
| return $subscription_data; | |
| } | |
| add_filter( 'leaky_paywall_create_stripe_plan', 'omg_add_vat_tax_to_stripe_plan', 10, 3 ); | |
| function omg_add_vat_tax_to_stripe_plan( $args, $level, $level_id ) { | |
| if ( isset( $_COOKIE['leaky-paywall-coupon'] ) ) { | |
| $stripe_amount = $level['price'] * 100; | |
| } else { | |
| $stripe_amount = $args['amount']; // 3500 | |
| } | |
| $regular_amount = $stripe_amount / 100; // 35.00 | |
| $regular_with_vat = omg_calculate_vat_total( $regular_amount ); | |
| $regular_with_vat_striped = $regular_with_vat * 100; | |
| $args['amount'] = $regular_with_vat_striped; | |
| return $args; | |
| } | |
| function omg_calculate_vat_total( $amount ) { | |
| $vat_tax = $amount * 0.21; // 21% | |
| $total_with_vat = $amount + $vat_tax; | |
| return number_format( $total_with_vat, 2 ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment