Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active October 18, 2023 13:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/9fe4b72ef5c793eb1d19c00839a08157 to your computer and use it in GitHub Desktop.
Save andrewlimaza/9fe4b72ef5c793eb1d19c00839a08157 to your computer and use it in GitHub Desktop.
Automatically apply discount code to checkout for Paid Memberships Pro.
<?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