我有一个开发人员为我编写了这个插件,以添加功能以通过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);
答案 0 :(得分:1)
有人可以解释代码表明我将使用的代码吗 它吗?
函数import_pricing_fields()
被挂接到'pmxi_saved_post'
动作中。
http://www.wpallimport.com/documentation/advanced/action-reference/
这意味着每次使用WP All Import导入post
时,它还将运行功能import_pricing_fields()
。
但这是在运行此函数中的大多数代码之前要通过的一项检查,即第4行if($post_type == 'product' || $post_type == 'product_variation' )
。这只是意味着post
是product
还是product_variation
继续运行此代码。
其余代码看起来像您所说的一样,导入批量定价...