Advertisement
designbymerovingi

Example: Set posts for sale by default

Jun 11th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. add_action( 'transition_post_status', 'mycredpro_all_content_for_sale', 99, 3 );
  2. function mycredpro_all_content_for_sale( $new_status, $old_status, $post ) {
  3.  
  4. // Make sure this is only applied to "Posts" and no other point type
  5. if ( ! isset( $post->post_type ) || $post->post_type != 'post' ) return;
  6.  
  7. // Make sure the post is transitioning from not being published to being published e.g. Draft > Publish
  8. if ( $new_status !== 'publish' || $old_status === 'publish' ) return;
  9.  
  10. // Get price
  11. $price = get_post_meta( $post->ID, 'ndna-price', true);
  12.  
  13. // Set post for sale
  14. $setup = array(
  15. 'status' => 'enabled', // enabled - for sale, disabled - not for sale
  16. 'price' => $price, // price in points
  17. 'button_label' => 'Get access to this lead', // the purchase button label
  18. 'expire' => 0 // Option to expire sale after x number of days
  19. );
  20.  
  21. // Save to enable
  22. update_post_meta( $post->ID, 'myCRED_sell_content', $setup );
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement