Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

WooCommerce创建一个自定义订单状态“Shipping”

在WordPress中使用WooCommerce创建一个自定义订单状态“Shipping”(发货中)涉及几个步骤。您需要编辑您的主题的 functions.php 文件或创建一个自定义插件来存放以下代码。以下是添加“Shipping”状态的步骤:

1. 注册新的订单状态

首先,您需要注册新的订单状态。这可以通过 wc_order_statuses 过滤器来完成。

add_filter( 'wc_order_statuses', 'add_custom_order_status_shipping' );

function add_custom_order_status_shipping( $order_statuses ) {
    $order_statuses['wc-shipping'] = _x( 'Shipping', 'Order status', 'textdomain' );
    return $order_statuses;
}

在这段代码中,wc-shipping 是新状态的内部名称,而 'Shipping' 是在订单管理页面上显示的状态名称。

2. 添加新状态到订单状态列表

接下来,您需要将新状态添加到订单编辑页面和订单筛选列表中。

add_action( 'init', 'register_custom_order_status_shipping' );
function register_custom_order_status_shipping() {
    register_post_status( 'wc-shipping', array(
        'label'                     => 'Shipping',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Shipping (%s)', 'Shipping (%s)', 'textdomain' )
    ) );
}

add_filter( 'wc_order_statuses', 'add_custom_order_status_to_filter_shipping' );
function add_custom_order_status_to_filter_shipping( $order_statuses ) {
    $order_statuses['wc-shipping'] = _x( 'Shipping', 'Order status', 'textdomain' );
    return $order_statuses;
}

这些代码创建了新的订单状态,并确保它出现在WooCommerce的后台界面中。

3. 国际化和本地化

如果您的站点支持多种语言,您需要将状态名称本地化。在上述代码中,textdomain 应该替换为您的主题或插件的文本域。

版权属于: sbboke版权所有。

转载时必须以链接形式注明作者和原始出处及本声明。

张贴在Wordpress标签:

相关文章

5 1 投票
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论