I have elaborated the attached code, in order to recall all the products purchased by a user. At this point, however, I would like to insert a condition such as: show only the products purchased in the last 3 days. However, I have never ventured into ifs by date. Anyone have any idea how to create such a condition?
<?php
$order_status = array_keys( wc_get_order_statuses());
$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
'numberposts' => - 1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types( 'view-orders' ),
'post_status' => $order_status,
) ) );
foreach ( $customer_orders as $customer_order ) {
$order = new WC_Order( $customer_order );
foreach ( $order->get_items() as $item_id => $item ) :
endforeach;
$date = esc_html( wc_format_datetime( $order->get_date_created() ) );
?>
<?php $date_comp = $order->get_date_completed(); ?>
<?php $product = wc_get_product( $item->get_product_id() ); ?>
<?php $product_id = $item->get_product_id(); ?>
}
2
Answers
I used to select orders using these conditions
You can use
wc_get_orders
where you can passdate_created
param. for more information check here – WC_Order_Query. try the below code.OR you can use
date_query
inget_posts
.