Hide a specific action button conditionally in Woocommerce admin Orders list

依然范特西╮ 提交于 2019-12-04 21:04:30

With CSS it's not be possible.

Instead you can hook in woocommerce_admin_order_actions filter hook, where you will be able to check if all order item are downloadable and then remove the action button "dispatch":

add_filter( 'woocommerce_admin_order_actions', 'custom_admin_order_actions', 900, 2 );
function custom_admin_order_actions( $actions, $the_order ){
    // If button action "dispatch" doesn't exist we exit
    if( ! $actions['dispatch'] ) return $actions;

    // Loop through order items
    foreach( $the_order->get_items() as $item ){
        $product = $item->get_product();
        // Check if any product is not downloadable
        if( ! $product->is_downloadable() )
            return $actions; // Product "not downloadable" Found ==> WE EXIT
    }
    // If there is only downloadable products, We remove "dispatch" action button
    unset($actions['dispatch']);

    return $actions;
}

Code goes in function.php file of the active child theme (or active theme).

This is untested but should work…

You will have to check that 'dispatch' is the correct slug for this action button…

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!