Created
August 31, 2015 07:08
-
-
Save bekarice/397c24bdf46eb5c0d5ff to your computer and use it in GitHub Desktop.
Dev Docs Example: WooCommerce Memberships product notice for non-members
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 | |
// Display a top notice to non-members for members-only products | |
function sv_members_only_product_notice() { | |
if ( ! function_exists( 'wc_memberships' ) ) { | |
return; | |
} | |
$user_id = get_current_user_id(); | |
// Bail if the user is already a silver or gold member | |
if ( wc_memberships_is_user_active_member( $user_id, 'silver' ) || wc_memberships_is_user_active_member( $user_id, 'gold' ) ) { | |
return; | |
} | |
// Add our top notice if purchasing is restricted | |
if ( wc_memberships_is_product_purchasing_restricted() ) { | |
wc_print_notice( 'This is a preview! Only silver or gold members can purchase this product.', 'notice' ); | |
} | |
} | |
add_action( 'woocommerce_before_single_product', 'sv_members_only_product_notice' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment