Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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_discunt_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_discunt_code_field_if_available' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment