如何在WooCommerce中按付款​​方式对订单排序?

时间:2019-09-05 13:33:20

标签: woocommerce

我只想查看BACS / PayPal购买的那些订单? 我可以通过WooCommerce >>订单在管理员中按付款方式对订单进行排序吗?

1 个答案:

答案 0 :(得分:0)

在活动主题的functions.php中添加以下代码段-

/**
 * Add payment method bulk filter for orders
 */
function add_filter_by_payment_method_orders() {
    global $typenow;
    if ( 'shop_order' === $typenow ) {
        // get all payment methods
        $gateways = WC()->payment_gateways->payment_gateways();
        ?>
        <select name="_shop_order_payment_method" id="dropdown_shop_order_payment_method">
            <option value=""><?php esc_html_e( 'All Payment Methods', 'text-domain' ); ?></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
    }
}
add_action( 'restrict_manage_posts', 'add_filter_by_payment_method_orders', 99 );

/**
 * Process bulk filter order for payment method
 *
 */
function add_filter_by_payment_method_orders_query( $vars ) {
    global $typenow;
    if ( 'shop_order' === $typenow && isset( $_GET['_shop_order_payment_method'] ) ) {
        $vars['meta_key']   = '_payment_method';
        $vars['meta_value'] = wc_clean( $_GET['_shop_order_payment_method'] );
    }
    return $vars;
}
add_filter( 'request', 'add_filter_by_payment_method_orders_query', 99 );