显示 WooCommerce 类别总销售额

时间:2021-04-26 18:30:50

标签: php wordpress woocommerce

我正在我的网站上设置会员部分,我需要显示单个类别(包括可变产品)的销售数量。我正在使用下面的代码段,我找到了 here,添加了我的类别,但我仍在获取整个商店的数量。

function memberships_sales_counter( $atts, $content = null ) {

    $args = shortcode_atts( array(
        'status' => 'completed',
        'product_cat' => 'cursos'
    ), $atts );

    $statuses = array_map( 'trim', explode( ',', $args['status'] ) );
    $order_count = 0;

    foreach ( $statuses as $status ) {
        // if we didn't get a wc- prefix, add one
        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( 'memberships-sales-counter', 'memberships_sales_counter' );

澄清一下,我不需要收入金额,我只需要计算销售总数。

0 个答案:

没有答案
相关问题