Fany_VanDaal icon

Zobrazení počtu objednávek na frontendu

Fany_VanDaal | PRO | 09/04/22 12:08:18 PM UTC (Edited) | 0 ⭐ | 1414 👁️ | Never ⏰ | []
PHP |

940 B

|

None

|

0 👍

/

0 👎

// Zobrazte kdekoliv na webu počet všech objednávek, které jste na shopu zrealizovali
// příklad shortcode [wc_pocet_objednavek status="completed,pending"]
// nebo použijte jen [wc_pocet_objednavek] pro zobrazení všech objednávek
// lze použít filtraci podle následujících stavů objednávek:
// completed
// processing
// on-hold
// pending
// cancelled
// refunded
// failed
 
function zobrazit_pocet_objednavek( $atts, $content = null ) {
    $args = shortcode_atts( array(
        'status' => 'completed',
    ), $atts );
    $statuses    = array_map( 'trim', explode( ',', $args['status'] ) );
    $order_count = 0;
    foreach ( $statuses as $status ) {
        if ( 0 !== strpos( $status, 'wc-' ) ) {
            $status = 'wc-' . $status;
        }
        $order_count += wp_count_posts( 'shop_order' )->$status;
    }
    ob_start();
    echo number_format( $order_count );
    return ob_get_clean();
}
add_shortcode( 'wc_pocet_objednavek', 'zobrazit_pocet_objednavek' );
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎