根据订单运送方式突出显示 WooCommerce 管理订单列表

问题描述 投票:0回答:2

我正在寻找一种根据订单运送方式突出显示管理订单列表行的方法。 (专供本地取货)

基于 根据订单付款方式突出显示 WooCommerce 管理订单列表 anwser 代码,我已将 $ payment_method 更改为 $shipping_method 并将 .type-shop_order.cod 更改为 .type-shop_order.local_pickupcode 用于运输方法,但它在管理面板中没有执行任何操作 我也尝试过使用运输方法标题而不是 $shipping_method,但它没有任何作用。

我也尝试过所有课程

public function get_shipping_classes() {
        if ( empty( $this->shipping_classes ) ) {
            $classes                = get_terms(
                'product_shipping_class',
                array(
                    'hide_empty' => '0',
                    'orderby'    => 'name',
                )
            );
            $this->shipping_classes = ! is_wp_error( $classes ) ? $classes : array();
        }
        return apply_filters( 'woocommerce_get_shipping_classes', $this->shipping_classes );
    }

但它隐藏了除本地取货之外的所有订单。

这是代码:

function filter_post_class( $classes, $class, $post_id ) {
    // Determines whether the current request is for an administrative interface page
    if ( ! is_admin() ) return $classes;

    // Get the current screen object
    $current_screen = get_current_screen();

    // Only when
    if ( $current_screen->id === 'edit-shop_order' ) {
        // Get an instance of the WC_Order object
        $order = wc_get_order( $post_id );

        // Is a WC_Order
        if ( is_a( $order, 'WC_Order' ) ) {
            // Get the payment method
            $shipping_method = $order->get_shipping_method();
            
             //NOT empty
            if ( ! empty( $shipping_method ) ) {
                $classes[] = $shipping_method;
            }
        }
    }
 
    // Return the array
    return $classes;
}
add_filter( 'post_class', 'filter_post_class', 10, 3 );

// Add CSS
function action_admin_head() {
    // Get the current screen object
    $current_screen = get_current_screen();

    // Only when
    if ( $current_screen->id === 'edit-shop_order' ) {
        echo '<style>
            .type-shop_order.local_pickup {
                background-color: #e9a5a5 !important;
            }
            
        </style>';
    }
}
add_action( 'admin_head', 'action_admin_head' );

请问如何更改有什么建议吗?我不是 php 编码员,所以这有点谷歌为我尝试的东西:/

php wordpress woocommerce
2个回答
0
投票

感谢CBroe,我成功了。

function filter_post_class( $classes, $class, $post_id ) {
    // Determines whether the current request is for an administrative interface page
    if ( ! is_admin() ) return $classes;

    // Get the current screen object
    $current_screen = get_current_screen();

    // Only when
    if ( $current_screen->id === 'edit-shop_order' ) {
        // Get an instance of the WC_Order object
        $order = wc_get_order( $post_id );

        // Is a WC_Order
        if ( is_a( $order, 'WC_Order' ) ) {
            // Get the shipping method
            $shipping_method = @array_shift($order->get_shipping_methods());
            $shipping_method_id = $shipping_method['method_id'];
            
             //NOT empty
            if ( ! empty( $shipping_method ) ) {
                $classes[] = $shipping_method_id;
            }
        }
    }
 
    // Return the array
    return $classes;
}
add_filter( 'post_class', 'filter_post_class', 10, 3 );

// Add CSS
function action_admin_head() {
    // Get the current screen object
    $current_screen = get_current_screen();

    // Only when
    if ( $current_screen->id === 'edit-shop_order' ) {
        echo '<style>
            .type-shop_order.local_pickup {
                background-color: #e9a5a5 !important;
            }
            
        </style>';
    }
}
add_action( 'admin_head', 'action_admin_head' );

0
投票

我正在寻找类似的东西,如果有任何善良的编码员愿意让我免去与愤怒的客户打交道的麻烦,那么我很感激。我们提供免费标准送货方式以及“上午 10 点前”和“周六早上”送货服务。我们的绝大多数订单都是免费和标准的,并且处理速度相同且快速。然而,我经常错过“Pre10”和“周六”的交付,因为它们是例外。我希望能够添加彩色背景或其他图标或方法来突出显示管理面板中的这些订单,因为它们经常被错过。

© www.soinside.com 2019 - 2024. All rights reserved.