Advertisement
Fany_VanDaal

Zobrazení počtu objednávek na frontendu

Sep 4th, 2022 (edited)
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. // Zobrazte kdekoliv na webu počet všech objednávek, které jste na shopu zrealizovali
  2. // příklad shortcode [wc_pocet_objednavek status="completed,pending"]
  3. // nebo použijte jen [wc_pocet_objednavek] pro zobrazení všech objednávek
  4. // lze použít filtraci podle následujících stavů objednávek:
  5. // completed
  6. // processing
  7. // on-hold
  8. // pending
  9. // cancelled
  10. // refunded
  11. // failed
  12.  
  13. function zobrazit_pocet_objednavek( $atts, $content = null ) {
  14.     $args = shortcode_atts( array(
  15.         'status' => 'completed',
  16.     ), $atts );
  17.     $statuses    = array_map( 'trim', explode( ',', $args['status'] ) );
  18.     $order_count = 0;
  19.     foreach ( $statuses as $status ) {
  20.         if ( 0 !== strpos( $status, 'wc-' ) ) {
  21.             $status = 'wc-' . $status;
  22.         }
  23.         $order_count += wp_count_posts( 'shop_order' )->$status;
  24.     }
  25.     ob_start();
  26.     echo number_format( $order_count );
  27.     return ob_get_clean();
  28. }
  29. add_shortcode( 'wc_pocet_objednavek', 'zobrazit_pocet_objednavek' );
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement