Skip to content

Instantly share code, notes, and snippets.

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 JarrydLong/0f952dae2c804daaf6e3a837095db5b0 to your computer and use it in GitHub Desktop.
Save JarrydLong/0f952dae2c804daaf6e3a837095db5b0 to your computer and use it in GitHub Desktop.
<?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