php - 如何在 WooCommerce 中使用自定义订单状态更改订单状态
问题描述
你好,我有这个代码,它添加了一个名为退款的自定义状态到订单状态
function register_awaiting_shipment_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => 'Return',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Return <span class="count">(%s)</span>', 'Return <span class="count">(%s)</span>' )
) );
register_post_status( 'wc-refund-issued', array(
'label' => 'Refund Issued',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Refund Issued<span class="count">(%s)</span>', 'Refund Issued <span class="count">(%s)</span>' )
) );
}
add_action( 'init', 'register_awaiting_shipment_order_status' );
// Add to list of WC Order statuses
function add_awaiting_shipment_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-awaiting-shipment'] = 'Return';
$new_order_statuses['wc-refund-issued'] = 'Refund Issued';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );
我希望能够通过
$order->status_update('refund issued');
但它不起作用它只适用于 woocommerce 已经附带的状态,例如处理和待付款,当我运行代码时它会将状态更改为待付款而不是退款我做错了什么?最后,我试图完成的是在查看订单区域中制作退款按钮,以便用户可以向当前订单发出退款请求
解决方案
问题解决了我说错了它应该是
$order->status_update('wc-refund-issued');
代替
$order->status_update('refund issued');
非常感谢
推荐阅读
- python-3.x - 如何获取 numpy.ndarray 的索引
- python - 替换多个(特殊)字符 - 最有效的方法?
- excel - 从字符串中提取数字作为整数
- javascript - javascript SyntaxError:标识符“img”已被声明
- node.js - 使用 Firebase Admin Auth 检索用户数据的费用
- c# - 如果我尝试打开 PWM 引脚,Windows 10 Iot Core 应用程序会崩溃
- ruby-on-rails - Rails 活动记录数组计数为 0,但数据库中存在记录?
- python - 即使形状存在,也缺少形状参考
- google-maps - 是否可以将 3D 模型上传到 Google 地图?
- c64 - “?Out of data error in 60”在我的 C64 mini 上基本