Last active
December 21, 2023 05:26
-
-
Save techjewel/5e11a448a5b7cf9e079eba157c0534a8 to your computer and use it in GitHub Desktop.
Filter WooCommerce orders by payment gateway
This file contains 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 // do not include this line in FluentSnippets | |
add_action('woocommerce_order_list_table_restrict_manage_orders', function($type) { | |
if ( 'shop_order' !== $type ) { | |
return; | |
} | |
// get all payment methods, even inactive ones | |
$gateways = WC()->payment_gateways->get_available_payment_gateways(); | |
?> | |
<select name="_shop_order_payment_method" id="dropdown_shop_order_payment_method"> | |
<option value=""> | |
<?php esc_html_e( 'All Payment Methods', 'wc-filter-orders-by-payment' ); ?> | |
</option> | |
<?php foreach ( $gateways as $id => $gateway ) : ?> | |
<option value="<?php echo esc_attr( $id ); ?>" <?php echo esc_attr( isset( $_GET['_shop_order_payment_method'] ) ? selected( $id, $_GET['_shop_order_payment_method'], false ) : '' ); ?>> | |
<?php echo esc_html( $gateway->get_method_title() ); ?> | |
</option> | |
<?php endforeach; ?> | |
</select> | |
<?php | |
}, 20, 1); | |
add_filter('woocommerce_order_list_table_prepare_items_query_args', function($args) { | |
if ( isset( $_GET['_shop_order_payment_method'] ) && ! empty( $_GET['_shop_order_payment_method'] ) ) { | |
$args['payment_method'] = wc_clean( $_GET['_shop_order_payment_method'] ); | |
} | |
return $args; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment