Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function pmpro_woo_make_single_product_purchasable( $is_purchasable, $product ) {
- // if the user currently has a membership level, just return current state of the product, else check it.
- if( pmpro_hasMembershipLevel() ) {
- return $is_purchasable;
- }else{
- return ( $product->id != 80 ? false : $is_purchasable ); //change product ID value of the product you want to sell to non-members.
- }
- }
- add_filter('woocommerce_is_purchasable', 'pmpro_woo_make_single_product_purchasable', 10, 2);
- function remove_my_woo_prices( $price, $product ) {
- global $pmprowoo_product_levels;
- //no product levels or PMProWC not active
- if( empty( $pmprowoo_product_levels ) ){
- return '';
- }
- //check if the product is a membership level
- $product_ids = array_keys( $pmprowoo_product_levels );
- if( !in_array( $product->get_id(), $product_ids ) ) {
- return '';
- }
- //must be a level product
- return $price;
- }
- function hide_prices_for_non_pmpro_members(){
- //if user has a PMPro membership level simply return.
- if( pmpro_hasMembershipLevel() ){
- return;
- }
- //set price of all products to NULL
- add_filter( 'woocommerce_variable_sale_price_html', 'remove_my_woo_prices', 10, 2 );
- add_filter( 'woocommerce_variable_price_html', 'remove_my_woo_prices', 10, 2 );
- add_filter( 'woocommerce_get_price_html', 'remove_my_woo_prices', 10, 2 );
- //hide the sales badge
- add_filter('woocommerce_sale_flash', '__return_false');
- }
- add_action( 'wp', 'hide_prices_for_non_pmpro_members' );
Add Comment
Please, Sign In to add comment