douyi6168 2015-09-11 03:01
浏览 71
已采纳

Woocommerce Order / AFC get_sub_field / get_sub_field_object(array)

Have setup ACF repeater field that stores various amount of tracking numbers in the order. Having 0 success with retrieving this information so need some advice.

Am using this to put information in subfields and it does the job

foreach ($base->DocumentLines->DocumentLine as $item) {

    foreach ($item->MiscData as $misc) {

        foreach ($misc->PackageNo as $package) {

            $trackno = (string)$package->TrackingNo;

            update_post_meta("$order_id", $field_rep, $count);

            $sub = $count +1;

            update_sub_field(array($field_key_rep, $sub, $field_key_sub), $trackno, "$order_id");

            $count = $count + 1;

            update_field($field_key, $trackno, "$order_id");

        }
    }
}

This works well, but then i need to retrieve this numbers and write em out. They are getting included in an email so need to retrieve the data outside of order.

Before rebuilding the function to be able to handle multiple numbers i did use a single field and could retrieve the information with

get_post_meta($order_id, 'tracking', true);

Feels like i have been trying everything now but got absolutely nothing.

Image from one of the orders, in this one it’s 10 tracking numbers but it varies from 1 to 20 if it's to any help.

enter image description here

  • 写回答

1条回答 默认 最新

  • dongxing1853 2015-09-13 04:53
    关注

    The feeling when you realize after 10 hours that your missed a capital letter in sub field name.

    Just wanted to submit my solution and hopefully it can help someone else having issues with ACF Repeater fields + Woocommerce

    For my specific case i did make a function that could extract all the tracking numbers my function above did add from XML files.

    $function trackingNo($postID) {
    
        $field_rep = 'trackingNo';
        $field_sub = 'no';
    
        if (have_rows($field_rep, $postID)) {
    
            $trackingNo = array();
    
        // loop through the rows of data
        while (have_rows($field_rep, $postID)):
            the_row();
    
            // Add to array
            $trackingNo[] = get_sub_field($field_sub);
    
        endwhile;
    
        $foo = implode('&consignmentId=', $trackingNo);
        $bar = 'urlzz/tracktrace/TrackConsignments_do.jsp?&consignmentId=';
    
        $value = $bar . $foo;
    
        return $value;
     }
    }
    

    Any advice for improvement is always welcome, my PHP is so'n'so :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧