WooCommerce订阅获得账单间隔和ID

时间:2019-03-15 19:38:15

标签: hook-woocommerce woocommerce-subscriptions

我正在使用条纹“ wc_gateway_stripe_process_response”来获取付款信息​​。需要的是该产品的付款间隔是多少,以及用户的订阅ID是什么。这是我到目前为止必须输入的代码:

 function woointerface_ProcessOrder($order_id) 
  {         
  $order               = new WC_Order( $order_id );                  
  $TransactionId       = $order->get_transaction_id();              
  $szOrderId           = $order->get_order_number();

  // Find all products associated with this order
 $order_data          = $order->get_data();                        
 $order_billing_email = $order->get_billing_email();                
 $payment_method      = $order->get_payment_method_title();         
 $PaymentDate         = $order->get_date_paid();
 $OrderNumber         = $order->get_order_number();

 $User      = get_user_by( 'email', $order_billing_email );             
 $FirstName = $User->first_name;
 $LastName  = $User->last_name;
 $UserId    = $User->ID;
 $PayerName = $FirstName . ' ' . $LastName;

  $items  = $order->get_items();
  foreach( $items as $item_id => $product )
    {   
  $ProductName         = $product->get_name();        
  $ProductId           = $product->get_product_id();  
  $PaymentAmount       = $product->get_total();     
  $ProductIndex        = wc_get_product($ProductId);

  if(! WC_Subscriptions_Product::is_subscription( $ProductIndex ) ) 
    continue;

 $UserSubscriptionId = ??
 $BillingCycle = ??


// Store in local table.

 }

寻找如何获取此订单的用户订阅ID和结算周期。

1 个答案:

答案 0 :(得分:0)

找到了计费和ID解决方案。以下呼叫为您提供帐单和用户订阅ID信息:

   $BillingCycle       = WC_Subscriptions_Product::get_interval($ProductIndex);  // how many times within the period to bill 
   $BillingPeriod      = WC_Subscriptions_Product::get_period($ProductIndex);    // Month/week/Year

   $subscriptions = wcs_get_subscriptions(array('order_id' => $order->id, 'product_id' => $ProductId));
   if (!empty($subscriptions)) 
   {
   $subscription = array_pop($subscriptions);
   $PaidSubscriptionId = $subscription->id;
   }