Advertisement
designbymerovingi

Max Content Sale

Oct 5th, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. /**
  2.  * Maximum Content Purchases
  3.  * Enforces a maximum number times a post can be purchased.
  4.  * @version 1.0
  5.  */
  6. function mycred_pro_limit_content_purchases( $buttons, $user_id, $post_id ) {
  7.  
  8.     if ( $buttons === false ) return $buttons;
  9.  
  10.     global $mycred_sold_out;
  11.  
  12.     $maximum_sales = 5;
  13.     $count         = mycred_count_ref_id_instances( 'buy_content', $post_id, NULL, MYCRED_DEFAULT_TYPE_KEY );
  14.  
  15.     // If we reached our limit, pretend the user can not afford to pay for this content
  16.     if ( $count >= $maximum_sales ) {
  17.  
  18.         $mycred_sold_out = true;
  19.  
  20.         return false;
  21.  
  22.     }
  23.  
  24.     return $buttons;
  25.  
  26. }
  27. add_filter( 'mycred_sellcontent_buttons', 'mycred_pro_limit_content_purchases', 10, 3 );
  28.  
  29. /**
  30.  * Sold Out Template
  31.  * @version 1.0
  32.  */
  33. function mycred_pro_show_sold_out_template( $template ) {
  34.  
  35.     global $mycred_sold_out;
  36.  
  37.     if ( $mycred_sold_out === true )
  38.         return '<p>This content has sold out.</p>';
  39.  
  40.     return $template;
  41.  
  42. }
  43. add_filter( 'mycred_sell_content_template', 'mycred_pro_show_sold_out_template' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement