Last active
October 18, 2023 13:24
-
-
Save andrewlimaza/9fe4b72ef5c793eb1d19c00839a08157 to your computer and use it in GitHub Desktop.
Automatically apply discount code to checkout for Paid Memberships Pro.
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 | |
/** | |
* Automatically apply a discount code to Paid Memberships Pro checkout. | |
* Adjust the discount code that should apply to all checkouts. | |
* If another discount code is set, use that as prefernce. | |
* | |
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_apply_discount_code() { | |
// Check if we're on the checkout page without a discount code already set. | |
if ( empty( $_REQUEST['level'] ) || ! empty( $_REQUEST['discount_code'] ) ) { | |
return; | |
} | |
$code = 'SE217EA4DA7'; //Change code here. Hint: Use a discount code for all levels to automatically apply it. | |
if ( pmpro_checkDiscountCode( $code, $_REQUEST['level'] ) ) { | |
$_REQUEST['discount_code'] = $code; | |
} | |
} | |
add_action( 'init', 'my_pmpro_apply_discount_code' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment