dougui2254 2018-10-29 20:46
浏览 38

在Wp导出函数编辑器中构建函数以获取产品的类别ID

So far i've got this code, and does return back all category ids on same row. The plugin doesn't allow me to export those products, it gives me error on export. Just to let you know, i do not have a product with more categories, every product have only one category. My xml editor looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<offers>
    <!-- BEGIN LOOP -->
    <offer id="{ID}" available="true">
        <URL>{Permalink}</URL>
        <name>{Title}</name>
        <price>{Sale Price}</price>
        <oldprice>{Regular Price}</oldprice>
        <picture>{Image URL}</picture>
        <currencyID>RON</currencyID>
        <vendor>Dealzz</vendor>
        <CategoryID>{fb_product_group_id}</CategoryID>
        <description>[wp_filter_nohtml_kses({Content})]</description>
        <test>[get_my_prod_cat_ids($prod_id)]</test>
    </offer>
    <!-- END LOOP -->
</offers>

this function is inside of function editor:

<?php
         function get_my_prod_cat_ids($prod_id) {
        $terms = get_the_terms( $prod_id, 'product_cat' );
        if($terms) {
            foreach ($terms as $key => $term) {
                $cats_ids_array[$key] = $term->term_id;

                //To get only the first category (uncomment below)
                break;
            }
            // to get an array replace below by: $output = $cats_ids_array;
            $output = implode( ",", $cats_ids_array ); 
            echo $output;
        }
    }
    ?>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用