Advertisement
designbymerovingi

Show myCRED Generated Coupons for Woo

Jan 2nd, 2015
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. /**
  2. * View my Coupons
  3. * @since 1.4
  4. * @version 1.1
  5. */
  6. add_shortcode( 'mycred_my_coupons', 'mycred_pro_render_shortcode_my_coupons' );
  7. function mycred_pro_render_shortcode_my_coupons( $attr, $content ) {
  8.  
  9. extract( shortcode_atts( array(
  10. 'user_id' => NULL,
  11. 'ctype' => 'mycred_default',
  12. 'ref' => 'points_to_coupon',
  13. 'number' => 10
  14. ), $attr ) );
  15.  
  16. if ( ! function_exists( 'mycred' ) ) return 'myCRED is not installed';
  17.  
  18. if ( $user_id === NULL && ! is_user_logged_in() ) return $content;
  19. if ( $user_id === NULL )
  20. $user_id = get_current_user_id();
  21.  
  22. $args = array();
  23.  
  24. $args['user_id'] = $user_id;
  25. $args['ref'] = $ref;
  26. $args['number'] = $number;
  27.  
  28. $log = new myCRED_Query_Log( $args );
  29.  
  30. $log->headers = array(
  31. 'coupon-code' => 'Coupon Code',
  32. 'coupon-status' => 'Status',
  33. 'coupon-date' => 'Date Created',
  34. 'coupon-value' => 'Value'
  35. );
  36.  
  37. ob_start();
  38.  
  39. if ( $log->have_entries() )
  40. $log->display();
  41.  
  42. else
  43. echo '<p>You do not have any coupons</p>';
  44.  
  45. $content = ob_get_contents();
  46. ob_end_clean();
  47.  
  48. return $content;
  49.  
  50. }
  51.  
  52. /**
  53. * View my Coupons Column : Code
  54. * @version 1.2
  55. */
  56. add_filter( 'mycred_log_coupon-code', 'mycred_pro_column_coupon_code', 10, 2 );
  57. function mycred_pro_column_coupon_code( $content, $log ) {
  58.  
  59. $data = maybe_unserialize( $log->data );
  60. return $data['code'];
  61.  
  62. }
  63.  
  64. /**
  65. * View my Coupons Column : Status
  66. * @version 1.0
  67. */
  68. add_filter( 'mycred_log_coupon-status', 'mycred_pro_column_coupon_status', 10, 2 );
  69. function mycred_pro_column_coupon_status( $content, $log ) {
  70.  
  71. if ( get_the_title( $log->ref_id ) == '' )
  72. return 'Used';
  73. else
  74. return 'Unused';
  75.  
  76. }
  77.  
  78. /**
  79. * View my Coupons Column : Date
  80. * @version 1.0
  81. */
  82. add_filter( 'mycred_log_coupon-date', 'mycred_pro_column_coupon_date', 10, 2 );
  83. function mycred_pro_column_coupon_date( $content, $log ) {
  84.  
  85. return date_i18n( 'Y-m-d', $log->time );
  86.  
  87. }
  88.  
  89. /**
  90. * View my Coupons Column : Value
  91. * @version 1.1
  92. */
  93. add_filter( 'mycred_log_coupon-value', 'mycred_pro_column_coupon_value', 10, 2 );
  94. function mycred_pro_column_coupon_value( $content, $log ) {
  95.  
  96. $data = maybe_unserialize( $log->data );
  97. if ( isset( $data['value'] ) )
  98. return '$' . $data['value'];
  99. else
  100. return '-';
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement