doupin5667 2019-07-08 05:32
浏览 51

创建php函数以检索woocommerce中的客户订阅续订订单状态?

PHP function to:

  • Get current customer ID
  • If customer has subscription proceed
  • If EXISTS -> Get latest customer subscription renewal order
  • Check status of renewal order (i.e. 'pending payment', 'on-hold', processing, 'complete')
  • RETURN status of renewal order

Here's what I have so far:

function get_last_customer_renewal_order() {
    $current_user_id = get_current_user_id();
    if (has_woocommerce_subscription('','','')){
    $subscriptions = wcs_get_users_subscriptions($current_user_id);
    $related_order_ID = array();
    $related_orders = array();
    foreach($subscriptions as $subscription) {
     // The subscription ID
     $related_order_ID[] = $subscription->get_related_orders( 'ids', 'renewal' );
     foreach($related_order_ID as $related_orders) {
         foreach($related_orders as $related_order) {
             $order = wc_get_order( print_r($related_order[0]));             
             echo $order->get_status;
         }   
    }
}
  • 写回答

1条回答 默认 最新

  • dongqian9013 2019-07-08 13:30
    关注

    UPDATE: So I've managed to retrieve the renewal ID, with the function below:

    function get_last_customer_renewal_order() {
        $current_user_id = get_current_user_id();
    
        if (has_woocommerce_subscription('','','')){
    
            $subscriptions = wcs_get_users_subscriptions($current_user_id);
            $related_order_ID = array();
            $related_orders = array();
    
            foreach($subscriptions as $subscription) {
    
             // The subscription ID
             $related_order_ID[] = $subscription->get_related_orders( 'ids', 'renewal' );
    
                foreach($related_order_ID as $related_orders) {
    
                    foreach($related_orders as $related_order) {
                        $order_id = $related_order;
    
                        if (! $order_id = ""){
                            $the_order_id = $related_order;
                            break 3;
                        }
                        else{
                        }
                    }
                }
            }
            //$order = wc_get_order($the_order_id);
            $order = new WC_Order( $the_order_id );
            $order_status = $order->get_status();
    
            //echo $the_order_id, '</br>', $order_status;
    
            return $order_status;
        }
        else{}
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了