Skip to content

Instantly share code, notes, and snippets.

add_filter('wp_all_import_set_post_terms', 'wpai_wp_all_import_set_post_terms', 10, 4);
function wpai_wp_all_import_set_post_terms($assign_terms, $tx_name, $pid, $import_id) {
if ($tx_name == 'product_cat'){
$post = get_post($pid);
if ($post->post_type == 'product_variation') {
$parentID = $post->post_parent;
$term_ids = wp_get_object_terms($parentID, $tx_name, array( 'fields' => 'ids' ));
if (!empty($assign_terms)) {
foreach ($assign_terms as $term_id) {
if (!in_array($term_id, $term_ids)) {
@cmdmcs
cmdmcs / gist:1c722b4574eba766b89cf8480fc6ac09
Last active November 2, 2018 14:10
delete images that have been unattached from properties (as they are no longer in the import file)
add_filter('wp_all_import_is_post_to_update', 'wpai_wp_all_import_is_post_to_update', 10, 5);
function wpai_wp_all_import_is_post_to_update($continueImport, $pid, $currentXmlNode, $importID, $simpleXml) {
$images = get_attached_media( 'image', $pid );
$ids = [];
foreach ($images as $image) {
$ids[] = $image->ID;
}
update_option('_wpai_attached_images_before_import_' . $pid, $ids);
return $continueImport;
}
add_action( 'pmxi_before_xml_import', 'wp_all_import_before_xml_import', 10, 1 );
function wp_all_import_before_xml_import( $import_id ) {
$path = false;
$import = new PMXI_Import_Record();
$import->getById( $import_id );
if ( ! $import->isEmpty() ) {
switch ($import->type) {
case 'url':