Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created February 7, 2023 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/4f05a2c9e5c99bd5f2f09105fd837ef4 to your computer and use it in GitHub Desktop.
Save kimcoleman/4f05a2c9e5c99bd5f2f09105fd837ef4 to your computer and use it in GitHub Desktop.
Hide the active sale from users with level ID 1, 2, or 3.
<?php
/**
* Hide the active sale from users with level ID 1, 2, or 3.
*/
function my_swsales_hide_from_premium_members( ) {
// Return early if this is the admin.
if ( is_admin() ) {
return;
}
// If user has membership, don't activate the sale.
if ( pmpro_hasMembershipLevel( array( 1, 2, 3 ) ) ) {
add_filter( 'option_swsales_options', 'unset_swsales_active_sale_id' );
}
}
add_action( 'init', 'my_swsales_hide_from_premium_members' );
/**
* Return 0 (no sale active) for the swsales_options option.
*/
function unset_swsales_active_sale_id() {
$option = array( 'active_sitewide_sale_id' => '0' );
return $option;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment