
Not:Bu kod WordPress 6.2 versionu ile test edilmiştir.
<?php
function dijitaloop_tarih_filtresi_ekle() {
if ( is_account_page() ) {
$orders_page_url = esc_url( wc_get_account_endpoint_url( 'orders' ) );
$current_url = home_url( add_query_arg( NULL, NULL ) );
$current_url_params = wp_parse_url( $current_url, PHP_URL_QUERY );
$orders_page_url_with_params = $orders_page_url;
if ( $current_url_params ) {
$orders_page_url_with_params .= '&' . $current_url_params;
}
?>
<form method="get" action="<?php echo $orders_page_url_with_params; ?>">
<label for="start_date"><?php esc_html_e('Başlangıç Tarihi:', 'text-domain'); ?></label>
<input type="date" id="start_date" name="start_date" value="<?php echo isset($_GET['start_date']) ? esc_attr($_GET['start_date']) : ''; ?>" style="width: 150px;"/>
<label for="end_date"><?php esc_html_e('Bitiş Tarihi:', 'text-domain'); ?></label>
<input type="date" id="end_date" name="end_date" value="<?php echo isset($_GET['end_date']) ? esc_attr($_GET['end_date']) : ''; ?>" style="width: 150px;"/>
<button type="submit"><?php esc_html_e('Filtrele', 'text-domain'); ?></button>
</form>
<?php
}
}
add_action('woocommerce_before_account_orders', 'dijitaloop_tarih_filtresi_ekle');
function dijitaloop_listele_tarih_araligi() {
if ( isset($_GET['start_date']) && isset($_GET['end_date']) && is_account_page() ) {
$start_date = sanitize_text_field($_GET['start_date']);
$end_date = sanitize_text_field($_GET['end_date']);
$current_user = wp_get_current_user();
$customer_orders = wc_get_orders( array(
'date_query' => array(
'relation' => 'AND',
array(
'after' => $start_date,
'inclusive' => true,
),
array(
'before' => $end_date,
'inclusive' => true,
),
),
'customer' => $current_user->ID,
) );
// Siparişleri listeleme işlemi
if ( $customer_orders ) {
?>
<table>
<thead style="background: #808080;color: #fff;">
<tr>
<th style="padding-left: 11px;">Sipariş Numarası</th>
<th style="padding-left: 11px;">Tarih</th>
<th style="padding-left: 11px;">Durum</th>
<th style="padding-left: 11px;">Toplam</th>
<th style="padding-left: 11px;">Eylem</th>
</tr>
</thead>
<tbody>
<?php
foreach ( $customer_orders as $order ) {
?>
<tr>
<td style="border: #000 1px 1px "><?php echo $order->get_order_number(); ?></td>
<td><?php echo $order->get_date_created()->date('Y-m-d'); ?></td>
<td><?php echo wc_get_order_status_name( $order->get_status() ); ?></td>
<td><?php echo wc_price( $order->get_total() ); ?></td>
<td><a href="<?php echo esc_url( $order->get_view_order_url() ); ?>" class="button"><?php esc_html_e( 'Siparişi Görüntüle', 'text-domain' ); ?></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
} else {
echo 'Belirtilen tarih aralığında sipariş bulunamadı.';
}
}
}
add_action('woocommerce_before_account_orders', 'dijitaloop_listele_tarih_araligi');