Forked from JarrydLong/mypmpro-hide-discount-field-specific-level.php
Last active
February 28, 2025 09:05
-
-
Save dwanjuki/c38901e780aa390d11688c3e69b9bd6f to your computer and use it in GitHub Desktop.
Show the discount code field on checkout for specified levels, hide on others
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 | |
/** | |
* Show the discount code field on checkout for specific levels only | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* | |
*/ | |
function my_pmpro_show_hide_discount_code() { | |
global $pmpro_show_discount_code; | |
if ( ! $pmpro_show_discount_code || ! function_exists( 'pmpro_getLevelAtCheckout' ) || ! function_exists( 'pmpro_is_checkout' ) ) { | |
return; | |
} | |
if ( pmpro_is_checkout() ) { | |
$level = pmpro_getLevelAtCheckout(); | |
if ( ! empty( $level ) ) { | |
$level_id = $level->id; | |
if ( ! in_array( $level_id , array( 2, 3 ) ) ) { // show discount code field for level 2 and 3 only | |
$pmpro_show_discount_code = false; | |
} | |
} | |
} | |
} | |
add_action( 'wp', 'my_pmpro_show_hide_discount_code' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment