Counting woocommerce orders returns status 500

While creating a function that returns an int counting the woocommerce orders status and the woocommerce order notes, I couldn’t make it work and I don’t know exactly what I’m doing it wrong.

I know that wc_orders_count( $status ) returns the orders count of a specific order status, if I am using the wrong function, wich must be used? and if I’m using it wrong, how must be used?

here is the function

add_action( ‘init’ ‘custom_counter’ );
function custom_counter() {
$customer_orders = get_posts( apply_filters( ‘woocommerce_my_account_my_orders_query’, array(
‘meta_key’ => ‘_customer_user’,
‘meta_value’ => get_current_user_id(),
‘post_type’ => wc_get_order_types( ‘view-orders’ ),
‘post_status’ => array_keys( wc_get_order_statuses() )
) ) );
if ( $customer_orders ) {
$status = wc_get_order( $customer_orders )->get_status();
$orderscounter = wc_orders_count( $status );
?>
<p class=”counter”>
<?php echo $orderscounter; ?>
</p>
<?php
}

Read more here:: Counting woocommerce orders returns status 500

Leave a Reply

Your email address will not be published. Required fields are marked *