我有一些自定义订单状态(使用 WooCommerce 订单状态管理器制作)。但是当我使用自定义付费状态时,预订状态不会更新为“付费”。我从各种参考资料中拼凑了一些代码,但这会导致致命错误。或者也许我错过了一些自定义状态应该更新预订支付状态而无需额外代码的东西?
我的代码:
add_action('woocommerce_order_status_pool-payment-rec','auto_change_booking_status_to_paid', 10, 1);
function auto_change_booking_status_to_paid($booking_id) {
$booking = new WC_Booking( $booking_id );
$order_id = $booking->get_order_id();
$booking->update_status('paid', 'order_note');
exit;
}
错误:
[20-Mar-2018 23:32:05 UTC] PHP Fatal error: Uncaught Exception: Invalid booking. in /home/ahbc/public_html/wp-content/plugins/woocommerce-bookings/includes/data-stores/class-wc-booking-data-store.php:83
Stack trace:
#0 /home/ahbc/public_html/wp-content/plugins/woocommerce/includes/class-wc-data-store.php(149): WC_Booking_Data_Store->read(Object(WC_Booking))
#1 /home/ahbc/public_html/wp-content/plugins/woocommerce-bookings/includes/data-objects/class-wc-booking.php(149): WC_Data_Store->read(Object(WC_Booking))
#2 /home/ahbc/public_html/wp-content/plugins/ahbc-website-tweaks/ahbc-website-tweaks.php(104): WC_Booking->__construct(2223)
#3 /home/ahbc/public_html/wp-includes/class-wp-hook.php(288): auto_change_booking_status_to_paid(2223)
#4 /home/ahbc/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
#5 /home/ahbc/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#6 /home/ahbc/public_html/wp-content/plugins/woocommerce/includes/class-wc-order.php(327): do_action('woocommerce_ord...', 2223, Object(WC_Order))
# in /home/ahbc/public_html/wp-content/plugins/woocommerce-bookings/includes/data-stores/class-wc-booking-data-store.php on line 83
我也试过这个,但它似乎什么也没做:
function sv_wc_order_statuses_needs_payment( $statuses, $order ) {
// use your custom order status slug here
$statuses[] = 'pool-payment-rec';
return $statuses;
}
add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', 'sv_wc_order_statuses_needs_payment', 10, 2 );
我的参考资料:
woocommerce 预订状态更改 woocommerce 订单状态
https://gist.github.com/bekarice/e922e79bc40eb0729095abc561cfe621
编辑:还尝试了以下几种变体:
add_action( 'woocommerce_order_status_changed', 'auto_change_booking_status_to_paid' );
function auto_change_booking_status_to_paid( $order_id ) {
if( ! $order_id ) return;
$order = wc_get_order($order_id);
$booking = get_wc_booking($booking_id);
if( $order->get_status() == 'test' )
// $order_id = $booking->get_order_id();
$booking->update_status('confirmed', 'order_note');
}