WooCommerce 管理订单列表中自定义订单状态的操作按钮问题

我还创建了自定义订单状态“准备发货”和自定义操作按钮。

问题和问题是:当我单击自定义操作按钮时,订单状态已更改,但默认操作按钮“完成”消失了。

单击自定义操作按钮后,如何才能保留“完成”操作按钮?

任何意见,将不胜感激

我目前的代码:

// Register new status
function register_awaiting_shipment_order_status() {
    register_post_status( 'wc-ready-to-dispatch', array(
        'label'                     => 'Ready to dispatch',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Ready to dispatch (%s)', 'Ready to dispatch (%s)' )
    ) );
}
add_action( 'init', 'register_awaiting_shipment_order_status' );

// Add your custom order status action button (for orders with "processing" status)
add_filter( 'woocommerce_admin_order_actions', 'add_custom_order_status_actions_button', 100, 2 );
function add_custom_order_status_actions_button( $actions, $order ) {
    // Display the button for all orders that have a 'processing' status
    if ( $order->has_status( array( 'processing' ) ) ) {

        $action_slug = 'ready-to-dispatch';

        // Get Order ID (compatibility all WC versions)
        $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
        // Set the action button
        $actions['ready-to-dispatch'] = array(
            'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=ready-to-dispatch&order_id=' . $order_id ), 'woocommerce-mark-order-status' ),
            'name'      => __( 'Ready to dispatch', 'woocommerce' ),
            'action'    => 'ready-to-dispatch', // keep "view" class for a clean button CSS
        );
    }
    return $actions;
}

// Set Here the WooCommerce icon for your action button
add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
    $action_slug = 'ready-to-dispatch';
    echo '<style>.wc-action-button-'.$action_slug.'::after { font-family: woocommerce !important; content: "\f344" !important; }</style>';
}

// Adding custom status 'awaiting-delivery' to order edit pages dropdown
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
  $new_order_statuses = array();

   // add new order status after processing
   foreach ( $order_statuses as $key => $status ) {

       $new_order_statuses[ $key ] = $status;

       if ( 'wc-processing' === $key ) {
           $new_order_statuses['wc-ready-to-dispatch'] = 'Ready to dispatch';
       }
   }

   return $new_order_statuses;
}


// Adding custom status 'awaiting-delivery' to admin order list bulk dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 1, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
    $actions['mark_ready-to-dispatch'] = __( 'Ready to dispatch', 'woocommerce' );
    return $actions;
}
7uc1f3r

这是因为在woocommerce_admin_order_actions钩子中缺少 if 条件,如果订单包含 status 则显示按钮ready-to-dispatch

我已经用这个更新的代码重写了你的代码。例如,init钩子已被替换woocommerce_register_shop_order_post_statuses为注册自定义订单状态。

所以你得到:

/**
 * Register order status
 */
function filter_woocommerce_register_shop_order_post_statuses( $order_statuses ) {
    // Status must start with "wc-"
    $order_statuses['wc-ready-to-dispatch'] = array(
        'label'                     => _x( 'Ready to dispatch', 'Order status', 'woocommerce' ),
        'public'                    => false,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        /* translators: %s: number of orders */
        'label_count'               => _n_noop( 'Ready to dispatch <span class="count">(%s)</span>', 'Abonnement <span class="count">(%s)</span>', 'woocommerce' ),       
    );
    
    return $order_statuses;
}
add_filter( 'woocommerce_register_shop_order_post_statuses', 'filter_woocommerce_register_shop_order_post_statuses', 10, 1 );

/**
 * Show order status in the dropdown @ single order
 */
function filter_wc_order_statuses( $order_statuses ) {  
    $new_order_statuses = array();

    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {

        $new_order_statuses[ $key ] = $status;

        if ( 'wc-processing' === $key ) {
            // Status must start with "wc-"
            $new_order_statuses['wc-ready-to-dispatch'] = _x( 'Ready to dispatch', 'Order status', 'woocommerce' );
        }
    }

    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'filter_wc_order_statuses', 10, 1 );

/**
 * Show order status in the dropdown @ bulk actions
 */
function filter_bulk_actions_edit_shop_order( $bulk_actions ) {
    // Note: "mark_" must be there instead of "wc"
    $bulk_actions['mark_ready-to-dispatch'] = __( 'Ready to dispatch', 'woocommerce' );
    return $bulk_actions;
}
add_filter( 'bulk_actions-edit-shop_order', 'filter_bulk_actions_edit_shop_order', 10, 1 );

/**
 * Add quick action button @ admin orders list
 */
function filter_order_actions( $actions, $order ) {
    // Get Order ID (compatibility all WC versions)
    $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
    
    // Display the button for all orders that have a 'processing' status
    if ( $order->has_status( array( 'processing' ) ) ) {

        $action_slug = 'ready-to-dispatch';

        // Set the action button
        $actions['ready-to-dispatch'] = array(
            'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=ready-to-dispatch&order_id=' . $order_id ), 'woocommerce-mark-order-status' ),
            'name'      => __( 'Ready to dispatch', 'woocommerce' ),
            'action'    => $action_slug, // keep "view" class for a clean button CSS
        );
    }
    
    // Display the button for all orders that have a 'ready-to-dispatch' status
    if ( $order->has_status( array( 'ready-to-dispatch' ) ) ) {
        
        $action_slug = 'complete';
    
        // Set the action button
        $actions['complete'] = array(
            'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order_id ), 'woocommerce-mark-order-status' ),
            'name'   => __( 'Complete', 'woocommerce' ),
            'action' => $action_slug,
        );
    }
    
    return $actions;
}
add_filter( 'woocommerce_admin_order_actions', 'filter_order_actions', 10, 2 );

/**
 *  Add WooCommerce icon for your action button @ admin orders list
 */
function action_admin_head() {
    $action_slug = 'ready-to-dispatch';
    echo '<style>.wc-action-button-' . $action_slug . '::after { content: "\f344" !important; }</style>';
}
add_action( 'admin_head', 'action_admin_head' );

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将img添加到Woocommerce的管理订单列表中的自定义操作按钮

单击以在WooCommerce管理订单列表中显示文本时隐藏自定义操作按钮

在WooCommerce管理订单列表中添加自定义操作按钮

在WooCommerce管理员订单列表中以批量操作添加自定义取消订单状态

Woocommerce 3.3管理员订单列表中的自定义订单状态背景按钮颜色

自定义操作按钮进入WooCommerce管理订单列表上的自定义列

在Woocommerce管理订单列表中显示具有“全部”自定义状态的订单

在Woocommerce中处理管理订单列表上的自定义批量操作

仅在WooCommerce管理员订单列表自定义列中显示特定订单状态的数据

在Woocommerce管理员订单列表上处理多个自定义批量操作

将自定义ajax按钮添加到WooCommerce管理订单列表

在Woocommerce 3中将自定义批量操作添加到管理订单列表

在 WooCommerce 管理订单列表的自定义列中显示私人和客户管理注释

后端订单列出了Woocommerce 3.3+中的自定义操作按钮

将自定义订单状态添加到WooCommerce管理员订单列表中的过滤器菜单

在Woocommerce管理员订单列表自定义列中显示结帐字段值

在Woocommerce管理订单列表中添加可排序的自定义列

在Woocommerce管理员订单列表自定义列中显示用户名

在Woocommerce管理员订单列表“订单”现有列中添加自定义字段

在 WooCommerce 管理订单列表的自定义列中显示每个订单项目的库存数量

在 WooCommerce 订单列表中显示 Dokan 自定义订单元数据

WooCommerce管理订单中的自定义操作按钮,用于发送电子邮件

WooCommerce的自定义订单列表页面

在WooCommerce中将自定义URL链接添加到管理订单列表页面

根据订单状态隐藏 WooCommerce 管理订单列表中的订单(表格行)

Woocommerce 3.3+中的预览灯箱上用于管理订单列表的其他操作按钮

WooCommerce - 自定义管理订单状态不起作用

在Woocommerce中每页自定义我的帐户订单列表帖子

如何根据状态隐藏 Woocommerce 订单列表中的订单