Last active
July 20, 2022 12:53
-
-
Save JarrydLong/0f952dae2c804daaf6e3a837095db5b0 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* This recipe will hide the discount code field on the checkout page if no discount codes | |
* have been created for that specific level. | |
* | |
* 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 mypmpro_show_discount_code_field_if_available(){ | |
global $pmpro_pages, $wpdb, $pmpro_show_discount_code; | |
if( is_page( intval( $pmpro_pages['checkout'] ) ) ) { | |
if( !empty( $_REQUEST['level'] ) ){ | |
$level_id = intval( $_REQUEST['level'] ); | |
$sql = "SELECT * FROM $wpdb->pmpro_discount_codes_levels cl | |
LEFT JOIN $wpdb->pmpro_discount_codes c | |
ON cl.level_id = c.id WHERE cl.level_id = '$level_id'"; | |
$results = $wpdb->get_results( $sql ); | |
if( !$results ) { | |
$pmpro_show_discount_code = false; | |
} | |
} | |
} | |
} | |
add_action( 'wp', 'mypmpro_show_discount_code_field_if_available' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment