Guest User

Untitled

a guest
Dec 15th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. function display_woocommerce_order_count2( $atts, $content = null ) {
  2. $args = shortcode_atts( array(
  3. 'status' => 'completed',
  4. ), $atts );
  5. $statuses = array_map( 'trim', explode( ',', $args['status'] ) );
  6. $order_count = 0;
  7. foreach ( $statuses as $status ) {
  8. // if we didn't get a wc- prefix, add one
  9. if ( 0 !== strpos( $status, 'wc-' ) ) {
  10. $status = 'wc-' . $status;
  11. }
  12. $order_count += wp_count_posts( 'shop_order' )->$status;
  13. }
  14. ob_start();
  15. return '<span style="color:#fff;text-align:center;font-size:12px">Deals:' .
  16. $order_count;
  17. $user->total;
  18. return ob_get_clean();
  19. }
  20. add_shortcode( 'wc_order_count3', 'display_woocommerce_order_count2' );
  21.  
  22. function get_instock_products_count(){
  23. global $wpdb;
  24.  
  25. // The SQL query
  26. $result = $wpdb->get_col( "
  27. SELECT COUNT(p.ID)
  28. FROM {$wpdb->prefix}posts as p
  29. INNER JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
  30. WHERE p.post_type LIKE '%product%'
  31. AND p.post_status LIKE 'publish'
  32. AND pm.meta_key LIKE '_stock_status'
  33. AND pm.meta_value LIKE 'instock'
  34. " );
  35.  
  36. return '<span style="color:#fff;text-align:center;font-size:12px">Proposals
  37. Left: ' . reset($result);
  38. }
  39. add_shortcode('fp7', 'get_instock_products_count');
  40.  
  41. function new_proposals2(){
  42. global $wpdb;
  43.  
  44. // 24 hours ago
  45. $is_24h_ago = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")." -1day"));
  46.  
  47. // The SQL query
  48. $result = $wpdb->get_col( "
  49. SELECT COUNT(p.ID)
  50. FROM {$wpdb->prefix}posts as p
  51. WHERE p.post_type LIKE '%product%'
  52. AND p.post_status LIKE 'publish'
  53. AND p.post_date > '$is_24h_ago'
  54. " );
  55.  
  56. return '<span style="color:#fff;text-align:center;font-size:12px">New
  57. Proposals: ' . reset($result);
  58. }
  59. add_shortcode( 'new_proposals', 'new_proposals2' );
  60.  
  61. function order_multi_count( $atts, $content = null ) {
  62. global $wpdb;
  63.  
  64. $args = shortcode_atts( array(
  65. 'status' => 'completed',
  66. ), $atts );
  67.  
  68. ## ---- ---- ---- ---- ---- ---- TAKEN ---- ---- ---- ---- ---- ---- ---- ##
  69.  
  70. $statuses = array_map( 'trim', explode( ',', $args['status'] ) );
  71. $taken = 0;
  72.  
  73. foreach ( $statuses as $status ) {
  74. // if we didn't get a wc- prefix, add one
  75. if ( 0 !== strpos( $status, 'wc-' ) ) {
  76. $status = 'wc-' . $status;
  77. }
  78. $taken += wp_count_posts( 'shop_order' )->$status;
  79. }
  80.  
  81. ## ---- ---- ---- ---- ---- ---- LEFT ---- ---- ---- ---- ---- ---- ---- ##
  82.  
  83. // The SQL query
  84. $result = $wpdb->get_col( "
  85. SELECT COUNT(p.ID)
  86. FROM {$wpdb->prefix}posts as p
  87. INNER JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
  88. WHERE p.post_type LIKE '%product%'
  89. AND p.post_status LIKE 'publish'
  90. AND pm.meta_key LIKE '_stock_status'
  91. AND pm.meta_value LIKE 'instock'
  92. " );
  93.  
  94. $left = reset($result);
  95.  
  96. ## ---- ---- ---- ---- ---- ---- NEW ---- ---- ---- ---- ---- ---- ---- ##
  97.  
  98. // 24 hours ago
  99. $is_24h_ago = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")." -1day"));
  100.  
  101. // The SQL query
  102. $result2 = $wpdb->get_col( "
  103. SELECT COUNT(p.ID)
  104. FROM {$wpdb->prefix}posts as p
  105. WHERE p.post_type LIKE '%product%'
  106. AND p.post_status LIKE 'publish'
  107. AND p.post_date > '$is_24h_ago'
  108. " );
  109.  
  110. $new = reset($result2);
  111.  
  112. ## ---- ---- ---- ---- ---- RETURNING VALUE ---- ---- ---- ---- ---- ---- ##
  113.  
  114. $style = 'style="color:#fff;text-align:center;font-size:12px"';
  115. return "<span $style><strong>Proposals:</strong> Taken ($taken) | New ($new) | Left ($left)</span>";
  116. }
  117. add_shortcode( 'order_multi_count', 'order_multi_count' );
Add Comment
Please, Sign In to add comment