gpt4 book ai didi

php - 在 Woocommerce 中添加自定义订单状态 "Shipped"

转载 作者:行者123 更新时间:2023-12-04 20:23:53 30 4
gpt4 key购买 nike

关闭。这个问题需要更多focused .它目前不接受答案。












想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post .

3年前关闭。




Improve this question




我正在使用 Woocommerce 开发一个电子商务网站,我希望自定义订单状态为“已发货”。

所以这就是流程的走向:客户下订单会收到一封电子邮件,说订单已确认,当前状态正在处理,管理员从其 express 员那里获取跟踪 ID,可以将其粘贴到新部分并将订单状态更改为已发货。这将向客户发送另一封带有跟踪 ID 的电子邮件。

是否有任何自定义代码可以帮助我实现此功能?

任何帮助将不胜感激。

最佳答案

以下代码将为 Woocommerce 订单添加一个新的自定义“已发货”订单状态:

// Register a custom order status
add_action('init', 'register_custom_order_statuses');
function register_custom_order_statuses() {
register_post_status('wc-shipped ', array(
'label' => __( 'Shipped', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>')
));
}


// Add a custom order status to list of WC Order statuses
add_filter('wc_order_statuses', 'add_custom_order_statuses');
function add_custom_order_statuses($order_statuses) {
$new_order_statuses = array();

// add new order status before processing
foreach ($order_statuses as $key => $status) {
$new_order_statuses[$key] = $status;
if ('wc-processing' === $key) {
$new_order_statuses['wc-shipped'] = __('Shipped', 'woocommerce' );
}
}
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', 50, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$new_actions = array();

// add new order status before processing
foreach ($actions as $key => $action) {
if ('mark_processing' === $key)
$new_actions['mark_shipped'] = __( 'Change status to shipped', 'woocommerce' );

$new_actions[$key] = $action;
}
return $new_actions;
}

// Add a 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', 'pending' or 'on-hold' status
if ( $order->has_status( array( 'on-hold', 'processing', 'pending' ) ) ) {

// The key slug defined for your action button
$action_slug = 'shipped';

// Set the action button
$actions[$action_slug] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status='.$action_slug.'&order_id='.$order->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Shipped', 'woocommerce' ),
'action' => $action_slug,
);
}
return $actions;
}

// Set styling for custom order status action button icon and List icon
add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
$action_slug = "shipped"; // The key slug defined for your action button
?>
<style>
.wc-action-button-<?php echo $action_slug; ?>::after {
font-family: woocommerce !important; content: "\e029" !important;
}
</style>
<?php
}
代码位于事件子主题(或事件主题)的 functions.php 文件中。测试和工作。
你会得到这样的东西:
在管理员订单列表中:
enter image description here
在管理订单编辑页面中:
enter image description here

从下拉订单批量操作中删除特定操作
例如我们要删除 “暂停” 状态改变:
add_filter( 'bulk_actions-edit-shop_order', 'remove_a_bulk_order_action', 20, 1 );
function remove_a_bulk_order_action( $actions ) {
unset($actions['mark_on-hold']);

return $actions;
}

All statuses change keys start with mark_ + the status slug (without wc-).

关于php - 在 Woocommerce 中添加自定义订单状态 "Shipped",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52097274/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com