Wp all import使用此功能检查sku是否存在并创建帖子。 但是我还有另一个导入,它使用更新功能更新帖子。如何在不每次手动更改代码的情况下使用它们?
<?php
function my_is_post_to_create( $continue_import, $data, $import_id ) {
// Get the SKU from the import file
$sku = $data['barcodeesterno']; // Change this to the column name that contains your SKU
global $wpdb;
// Check if the SKU already exists
$product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );
if ( $product_id ) {
// If product ID exists then skip importing
return false;
} else {
// Else, import the product
return true;
}
}
add_filter('wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3);
?>