Hide WooCommerce My Account Orders if total purchase amount is 0
P粉545956597
2023-08-17 21:18:54
<p>In woocommerce, I'm trying to hide an order if the order total is 0.
Below is my code but it doesn't work. Any thoughts on the problem? </p>
<pre class="brush:php;toolbar:false;">add_filter( 'woocommerce_my_account_my_orders_query',
'hide_zero_total_orders_from_my_account', 10, 1 );
function hide_zero_total_orders_from_my_account( $args ) {
$args['meta_query'] = array(
array(
'key' => '_order_total',
'value' => 0,
'compare' => '>',
'type' => 'NUMERIC',
),
);
return $args;
}</pre>
<p><br /></p>
You can use a lightweight SQL query to get the customer's total purchase amount and use that query to hide the "My Account Orders" section if the total purchase amount is equal to 0 (zero):
Place the code in your child theme’s functions.php file (or in a plugin). Tested and working fine.