【问题标题】:Show "complete" action button to WooCommerce order with a custom status向具有自定义状态的 WooCommerce 订单显示“完成”操作按钮
【发布时间】:2019-05-15 17:00:50
【问题描述】:

我使用以下代码添加了自定义 WooCommerce 状态并希望

function register_shipped_status() {

    register_post_status( 'wc-shipped', array(
        'label'                     => 'Shipped',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Versendet <span class="count">(%s)</span>', 'Versendet <span class="count">(%s)</span>' )
    ) );

}
add_action( 'init', 'register_shipped_status' );

function add_shipped_to_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-shipped'] = 'Versendet';
        }
    }

    return $new_order_statuses;

}
add_filter( 'wc_order_statuses', 'add_shipped_to_order_statuses' );

这工作正常。 WooCommerce 状态是可选择的,但我希望订单列表中的操作按钮“已完成”。

看截图:

有没有办法将此 WooCommerce 按钮添加到具有我的自定义 WooCommerce 状态的所有订单?

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce orders


    【解决方案1】:

    要为具有自定义订单状态的订单设置“完成”操作按钮,请使用以下命令:

    add_filter( 'woocommerce_admin_order_actions', 'customize_admin_order_actions', 10, 2 );
    function customize_admin_order_actions( $actions, $order ) {
        // Display the "complete" action button for orders that have a 'shipped' status
        if ( $order->has_status('shipped') ) {
            $actions['complete'] = array(
                'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
                'name'   => __( 'Complete', 'woocommerce' ),
                'action' => 'complete',
            );
        }
        return $actions;
    }
    

    代码在您的活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。

    相关:Add a custom order status "Shipped" in Woocommerce

    【讨论】:

    • 非常感谢。完美运行!
    猜你喜欢
    • 2016-04-17
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 2019-10-09
    • 2019-08-26
    • 2021-12-05
    • 2018-10-06
    相关资源
    最近更新 更多