我一直在使用此代码来处理续期付款。问题是这条线
$parent_id = WC_Subscriptions_Renewal_Order::get_parent_order_id( $subscription ); // <<<<< this is failing
最终会导致致命错误:
Fatal error: Uncaught Error: Call to a member function get_parent_id() on null in ....public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscriptions-renewal-order.php:315
目前我的代码是这样:
add_action( 'woocommerce_subscription_renewal_payment_complete', 'mmd_woocommerce_subscription_renewal_payment_complete', 1, 2); // The subscription renewal payment
function mmd_woocommerce_subscription_renewal_payment_complete($subscription, $last_order)
{
global $wpdb;
$SubscriptionNumber = $subscription->get_order_number();
$BusinessEmail = $subscription->get_billing_email();
$OrderNumber = $subscription->parent_id;
//***********************************
// Another way to get the Parent Order from the subscription.
$parent_id = WC_Subscriptions_Renewal_Order::get_parent_order_id( $subscription ); // <<<<< this is failing
$ParentOrder = new WC_Order( $parent_id );
//***********************************
foreach ( $subscription->get_items() as $item )
{
$NewExpiration = WC_Subscriptions_Order::get_next_payment_date ( $ParentOrder, $item['product_id'] ); /* This should get the next payment date... */
if ( $NewExpiration )
{
Do some work...
}
}
}
我需要另一种获取父订单ID的方法。有什么想法吗?
答案 0 :(得分:0)
@Debbie Kurth,您好:您很早以前就问过您的问题,所以也许这没有意义,但是也许其他有相同问题的人也会来这里。
WooCommerce不再允许直接访问某些订单属性,因此您需要使用相关的get_something()函数。
例如,代替$OrderNumber = $subscription->parent_id;
使用:$OrderNumber = $subscription->get_parent_id();