WooCommerce订阅-获取到期日期

时间:2019-03-25 作者:Debbie Kurth

使用回调挂钩,我可以获得除到期日期之外的所有订阅信息。有没有想过如何抓住这个机会。这就是我所拥有的:

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
  }
 }
这些电话:

 $ExpireDate = $sub->get_expiration_date( \'next_payment\' ); 

 $ExpireDate = WC_Subscriptions_Order::get_next_payment_date ( $ParentOrder, $ProductId  ); 
如果用户手动提前付款,则无效。它只返回下一个付款日期,而不是实际存储的到期日期

2 个回复
SO网友:bw1984

我有一个与你描述的问题相似的问题。最后我不得不woocommerce_subscription_status_active 您可以从中访问相关$subscription 对象作为单个参数。如果您需要标准中的任何进一步详细信息$order 对象,然后您可以通过$subscription->get_parent() 在您的职能范围内。

问题似乎是,附加到订阅的结束日期值只能按照挂钩/操作的顺序设置得非常晚,因此您通常在签出后使用的任何标准挂钩都可能无法访问订阅日期,因为它们仍然没有设置。

在我让它为我工作之前,我尝试了以下所有方法;

woocommerce_thankyou
woocommerce_payment_complete
woocommerce_checkout_order_processed
woocommerce_order_status_completed
woocommerce_subscription_payment_complete
在每种情况下,结束日期(和下一个付款日期)都是空的,尽管我以后可以在wordpress管理中看到它们。

SO网友:Antti Koskinen

根据文件(product, subscription) 我认为

WC_Subscriptions_Product::get_expiration_date( $ProductId );

WC_Subscription::get_date( \'end\' );
应返回到期日期。