Forked from messica/my_pmpro_applydiscountcode_return_js.php
Last active
February 5, 2019 10:37
-
-
Save travislima/dda9548d8085bc70126fc8575ed133b1 to your computer and use it in GitHub Desktop.
Display messages of the Original Price, Discounted Price and Amount Saved when discount code is applied to PMPro order.
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 | |
| /** | |
| * Display messages of the Original Price, Discounted Price and Amount Saved when discount code is applied to PMPro order. | |
| * Add this code recipe to a PMPro Customization Plugin - Display messages of the Original Price, Discounted Price and Amount Saved when discount code is applied to PMPro order | |
| * Various classes added to strings to allow for styling - ".pmpro-discorig-message", ".pmpro-orginal-price", ".pmpro-discount-price", ".pmpro-save-price" | |
| * | |
| * [my_pmpro_applydiscountcode_return_js] Display original price and discount when a discount code is applied. | |
| * @param string $discount_code [description] | |
| * @param integer $discount_code_id [description] | |
| * @param integer $level_id [description] | |
| * @param integer $code_level [description] | |
| * @return void | |
| */ | |
| function my_pmpro_applydiscountcode_return_js( $discount_code, $discount_code_id, $level_id, $code_level ) { | |
| // Get the original level. | |
| $level = pmpro_getLevel( $level_id ); | |
| // Format prices. | |
| $original_price = pmpro_formatPrice( $level->initial_payment ); | |
| $discounted_price = pmpro_formatPrice( $code_level->initial_payment ); | |
| $discount = $level->initial_payment - $code_level->initial_payment; | |
| $discount = pmpro_formatPrice( $discount ); | |
| // Build HTML. | |
| $html = "'<div class=\"pmpro-discorig-message pmpro-original-price\">The original price is {$original_price}. </div>"; | |
| $html .= "<div class=\"pmpro-discorig-message pmpro-discount-price\">The discounted price is {$discounted_price}. </div>"; | |
| $html .= "<div class=\"pmpro-discorig-message pmpro-save-price\">You save {$discount}.</div>'"; | |
| ?> | |
| jQuery("#pmpro_level_cost").html(<?php echo $html; ?>); | |
| <?php | |
| } | |
| add_action( 'pmpro_applydiscountcode_return_js', 'my_pmpro_applydiscountcode_return_js', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment