我一直在使用此代码来处理续期付款。问题是这条线
$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的方法。有什么想法吗?