Guest User

Untitled

a guest
Feb 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. function pmpro_woo_make_single_product_purchasable( $is_purchasable, $product ) {
  4. // if the user currently has a membership level, just return current state of the product, else check it.
  5. if( pmpro_hasMembershipLevel() ) {
  6. return $is_purchasable;
  7. }else{
  8. return ( $product->id != 80 ? false : $is_purchasable ); //change product ID value of the product you want to sell to non-members.
  9. }
  10. }
  11. add_filter('woocommerce_is_purchasable', 'pmpro_woo_make_single_product_purchasable', 10, 2);
  12.  
  13. function remove_my_woo_prices( $price, $product ) {
  14. global $pmprowoo_product_levels;
  15.  
  16. //no product levels or PMProWC not active
  17. if( empty( $pmprowoo_product_levels ) ){
  18. return '';
  19. }
  20.  
  21. //check if the product is a membership level
  22. $product_ids = array_keys( $pmprowoo_product_levels );
  23. if( !in_array( $product->get_id(), $product_ids ) ) {
  24. return '';
  25. }
  26.  
  27. //must be a level product
  28. return $price;
  29. }
  30.  
  31. function hide_prices_for_non_pmpro_members(){
  32.  
  33. //if user has a PMPro membership level simply return.
  34. if( pmpro_hasMembershipLevel() ){
  35. return;
  36. }
  37.  
  38. //set price of all products to NULL
  39. add_filter( 'woocommerce_variable_sale_price_html', 'remove_my_woo_prices', 10, 2 );
  40. add_filter( 'woocommerce_variable_price_html', 'remove_my_woo_prices', 10, 2 );
  41. add_filter( 'woocommerce_get_price_html', 'remove_my_woo_prices', 10, 2 );
  42.  
  43.  
  44. //hide the sales badge
  45. add_filter('woocommerce_sale_flash', '__return_false');
  46. }
  47.  
  48. add_action( 'wp', 'hide_prices_for_non_pmpro_members' );
Add Comment
Please, Sign In to add comment