WordPress插件函数

WordPress插件函数,wordpress,Wordpress,不久前,我让一位开发人员为我编写了这个插件,添加了通过WP All import将批量定价导入产品的功能。关于这件事,他一直没有回复我。我不得不删除我们一起设置的自动导入,我不记得如何使用它导入他构建的系统的批量定价。有人能解释一下代码表明我会如何使用它吗 <?php /* Plugin Name: WP All Import Woo Bulk Pricing Add-On Description: Import data related to bulk pricing Version:

不久前,我让一位开发人员为我编写了这个插件,添加了通过WP All import将批量定价导入产品的功能。关于这件事,他一直没有回复我。我不得不删除我们一起设置的自动导入,我不记得如何使用它导入他构建的系统的批量定价。有人能解释一下代码表明我会如何使用它吗

<?php
/*
Plugin Name: WP All Import Woo Bulk Pricing Add-On
Description: Import data related to bulk pricing
Version: 1.0    */
//  

function import_pricing_fields($id, $xml_node) {
    // return;
    $post_type = get_post_type($id);

    if($post_type == 'product' || $post_type == 'product_variation' ){
        $xml_node = (array) $xml_node;
        $_product = wc_get_product( $id );
        $number_of_prices = 3;
        if( $_product->is_type( 'simple' ) ) {
            update_post_meta($id,'_regular_price', $xml_node['price']);
            update_post_meta($id,'_price', $xml_node['price']);
            $pricing_array = array();
            for($i=1;$i<$number_of_prices;$i++){
                if(isset($xml_node['qb_'.$i]) && $xml_node['qb_'.$i] != 0){
                    $pricing_array[$i]['min'] = $xml_node['qb_'.$i];
                    if($i > 1){
                        $pricing_array[$i-1]['max'] = $xml_node['qb_'.$i]-1;
                        $pricing_array[$i]['max'] = "*";
                    } else {
                        $pricing_array[$i]['max'] = "*";
                    }
                    $pricing_array[$i]['val'] = $xml_node['price_'.$i];
                }
            }
            $pricing_array = array_values($pricing_array);


            if(!empty($pricing_array)) {
                update_post_meta($id,'_wc_bulk_pricing_ruleset','_custom');
                update_post_meta($id,'_wc_bulk_pricing_custom_ruleset', $pricing_array);
            }
        } else{
            $var_id = wc_get_product_id_by_sku($xml_node['catalog']);
            $variations = $_product->get_children();

            if(!empty($variations)) {
                foreach ($variations as $variation) {
                    $sku = get_post_meta($variation, '_sku', true);
                    if(!empty($sku) && $sku == $xml_node['catalog']) {
                        $var_id = $variation;
                    }
                }
            }


            update_post_meta($var_id,'_regular_price', $xml_node['price']);
            update_post_meta($var_id,'_price', $xml_node['price']);
            if(isset($xml_node['qb_1'])) {
                $pricing_array = array();
                for($i=1;$i<$number_of_prices;$i++){
                    if(isset($xml_node['qb_'.$i]) && $xml_node['qb_'.$i] != 0){
                        $pricing_array[$i]['min'] = $xml_node['qb_'.$i];
                        if($i > 1){
                            $pricing_array[$i-1]['max'] = $xml_node['qb_'.$i]-1;
                            $pricing_array[$i]['max'] = "*";
                        } else {
                            $pricing_array[$i]['max'] = "*";
                        }
                        $pricing_array[$i]['val'] = $xml_node['price_'.$i];
                    }
                }
                $pricing_array = array_values($pricing_array);


                if(!empty($pricing_array)) {
                    update_post_meta($var_id,'_wc_bulk_pricing_ruleset','_custom');
                    update_post_meta($var_id,'_wc_bulk_pricing_custom_ruleset', $pricing_array);
                }
            }

        }
    }
}
add_action('pmxi_saved_post','import_pricing_fields', 10, 2);
是_类型('simple')){
更新发布元($id,''u常规价格',$xml\u节点['price']);
更新发布元($id,'u price',$xml\u节点['price']);
$pricing_array=array();
对于($i=1;$i 1){
$pricing_数组[$i-1]['max']=$xml_节点['qb_'.$i]-1;
$pricing_数组[$i]['max']=“*”;
}否则{
$pricing_数组[$i]['max']=“*”;
}
$pricing_数组[$i]['val']=$xml_节点['price_'.$i];
}
}
$pricing\u array=数组值($pricing\u array);
如果(!空($U数组)){
更新发布元数据($id、'wc'批量定价规则集'、'custom');
更新发布元($id,“$wc\u批量\u定价\u自定义\u规则集,$pricing\u数组);
}
}否则{
$var_id=wc_get_product_id_by_sku($xml_节点['catalog');
$variations=$\u产品->获取子项();
如果(!空($variations)){
foreach($变更为$变更){
$sku=get_post_meta($variation,'u sku',true);
如果(!empty($sku)&&$sku==$xml\u节点['catalog']){
$var_id=$variation;
}
}
}
更新后置元($var\u id,''u常规价格',$xml\u节点['price']);
更新发布元($var\u id,''u price',$xml\u节点['price']);
if(isset($xml_节点['qb_1'])){
$pricing_array=array();
对于($i=1;$i 1){
$pricing_数组[$i-1]['max']=$xml_节点['qb_'.$i]-1;
$pricing_数组[$i]['max']=“*”;
}否则{
$pricing_数组[$i]['max']=“*”;
}
$pricing_数组[$i]['val']=$xml_节点['price_'.$i];
}
}
$pricing\u array=数组值($pricing\u array);
如果(!空($U数组)){
更新发布元($var\u id,“'u wc\u bulk\u pricing\u ruleset',“'u custom');
更新后置元($var\u id,''u wc\u批量定价\u自定义规则集',$pricing\u数组);
}
}
}
}
}
添加操作(“pmxi\U保存的\U post”和“导入\U定价\U字段”,10,2);
有人能解释一下代码表明我将如何使用它吗 是吗

函数
import\u pricing\u fields()
连接到
'pmxi\u saved\u post'
操作中

这意味着每次使用WP All import导入
post
时,它也将运行函数
import\u pricing\u fields()

但是,这是在该函数中的大多数代码运行之前要通过的一个检查,这是在第4行
if($post_type=='product'.|$$post_type=='product_variation')
。这意味着如果
post
product
product\u变体
继续运行此代码


代码的其余部分看起来与您所说的一样,导入批量定价…

谢谢。构建这个的程序员没有解释,并且忽略了我所有关于这个的电子邮件,我一直在尝试利用它的功能,但我所要求的并不是他所做的。