Forked from messica/my_pmpro_applydiscountcode_return_js.php
Last active
November 21, 2019 08:22
-
-
Save ipokkel/effbb6e6ad428b3f070376281973e71f to your computer and use it in GitHub Desktop.
Display original price and discount when a discount code is applied. Modified to display original price on discount code error
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 ) { | |
// Only continue if code is valid. | |
// if ( false == $code_level ) { | |
// return; | |
// } | |
// 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>'"; | |
if ( false == $code_level ) { | |
$html = "'<div class=\"pmpro-discorig-message pmpro-code-error-price\">The discount code applied is invalid. The price is {$original_price}</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