Last active
March 9, 2023 05:05
-
-
Save komal-maru/2601a1e5886dc55436f1c4c17e8999d7 to your computer and use it in GitHub Desktop.
Add a new WooCommerce order status into Dashboard status widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Add a WooCommerce order status (completed, refunded) into the Dashboard status widget | |
function woocommerce_add_order_status_dashboard_widget() { | |
if ( ! current_user_can( 'edit_shop_orders' ) ) { | |
return; | |
} | |
$refunded_count = 0; | |
$completed_count = 0; | |
foreach ( wc_get_order_types( 'order-count' ) as $type ) { | |
$counts = (array) wp_count_posts( $type ); | |
$refunded_count += isset( $counts['wc-refunded'] ) ? $counts['wc-refunded'] : 0; | |
$completed_count += isset( $counts['wc-completed'] ) ? $counts['wc-completed'] : 0; | |
} | |
?> | |
<li class="processing-orders"> | |
<a href="<?php echo admin_url( 'edit.php?post_status=wc-completed&post_type=shop_order' ); ?>"> | |
<?php | |
/* translators: %s: order count */ | |
printf( | |
_n( '<strong>%s order</strong> completed', '<strong>%s orders</strong> completed', $completed_count, 'woocommerce' ), | |
$completed_count | |
); | |
?> | |
</a> | |
</li> | |
<li class="refunded-orders"> | |
<a href="<?php echo admin_url( 'edit.php?post_status=wc-refunded&post_type=shop_order' ); ?>"> | |
<?php | |
/* translators: %s: order count */ | |
printf( | |
_n( '<strong>%s order</strong> refunded', '<strong>%s orders</strong> refunded', $refunded_count, 'woocommerce' ), | |
$refunded_count | |
); | |
?> | |
</a> | |
</li> | |
<?php | |
} | |
add_action( 'woocommerce_after_dashboard_status_widget', 'woocommerce_add_order_status_dashboard_widget' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment