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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器