Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionUsing the call back hook, I can get the subscription information of everything EXCEPT the expiration date. Any thoughts on how to grab this. This is what I have:
function mmd_woointerface_ProcessOrder($order_id)
{
$order = new WC_Order( $order_id );
$OrderNumber = $order->parent_id;
$ParentOrder = new WC_Order( $OrderNumber );
$TransactionId = $ParentOrder->get_transaction_id();
$DatePaid = $order->date_created;
$SubscriptionNumber = $order->get_order_number();
$PaymentDate = $order->get_date_created()->format ('Y-m-d');
$ProductId = $product->get_product_id();
$subscriptions = wcs_get_users_subscriptions( $UserId );
foreach ($subscriptions as $sub)
{
if($sub->ID == $SubscriptionNumber)
$ExpireDate = $sub->get_expiration_date( 'next_payment' ); <<NOT ACCURATE
$ExpireDate = WC_Subscriptions_Order::get_next_payment_date ( $ParentOrder, $ProductId ); << SAME PROBLEM
}
}
These calls:
$ExpireDate = $sub->get_expiration_date( 'next_payment' );
$ExpireDate = WC_Subscriptions_Order::get_next_payment_date ( $ParentOrder, $ProductId );
are not effective when you have a user who makes a manual early payment. It just returns the next payment date, verses the actual stored expiration date
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionUsing the call back hook, I can get the subscription information of everything EXCEPT the expiration date. Any thoughts on how to grab this. This is what I have:
function mmd_woointerface_ProcessOrder($order_id)
{
$order = new WC_Order( $order_id );
$OrderNumber = $order->parent_id;
$ParentOrder = new WC_Order( $OrderNumber );
$TransactionId = $ParentOrder->get_transaction_id();
$DatePaid = $order->date_created;
$SubscriptionNumber = $order->get_order_number();
$PaymentDate = $order->get_date_created()->format ('Y-m-d');
$ProductId = $product->get_product_id();
$subscriptions = wcs_get_users_subscriptions( $UserId );
foreach ($subscriptions as $sub)
{
if($sub->ID == $SubscriptionNumber)
$ExpireDate = $sub->get_expiration_date( 'next_payment' ); <<NOT ACCURATE
$ExpireDate = WC_Subscriptions_Order::get_next_payment_date ( $ParentOrder, $ProductId ); << SAME PROBLEM
}
}
These calls:
$ExpireDate = $sub->get_expiration_date( 'next_payment' );
$ExpireDate = WC_Subscriptions_Order::get_next_payment_date ( $ParentOrder, $ProductId );
are not effective when you have a user who makes a manual early payment. It just returns the next payment date, verses the actual stored expiration date
Share Improve this question asked Mar 25, 2019 at 5:59 Debbie KurthDebbie Kurth 4323 silver badges14 bronze badges2 Answers
Reset to default 1I had a similar problem to the one you have described. In the end i had to hook into woocommerce_subscription_status_active
from which you can access the related $subscription
object as a single argument. If you need any further details from the standard $order
object also then you can access that via $subscription->get_parent()
within your function.
The issue seems to be that the end date value attached to a subscription only gets set really late in the order of hooks/actions, so any of the standard hooks you would usually use post-checkout may not have access to the subscription dates yet since they are still not set.
I tried all of the following before i got it to work for me;
woocommerce_thankyou
woocommerce_payment_complete
woocommerce_checkout_order_processed
woocommerce_order_status_completed
woocommerce_subscription_payment_complete
and in each case the end date (and next payment date) were both empty even though i could see them in the wordpress admin later on.
Based on the documentation (product, subscription) I would assume that either
WC_Subscriptions_Product::get_expiration_date( $ProductId );
or
WC_Subscription::get_date( 'end' );
should return the expiration date.