Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Dieter Jeanty
Dieter Jeanty
292 Points

Woocommerce - WP All import - Only import draft code problem

Hi Treehouse team & community,

I was wondering if someone could help me with this. I am using wp all import to import some products. In total there are 5025 products where 500 are published and the rest is Draft. I am using wp all import to sync the stock but i want to update only the ones that are published so not the draft ones.

I contacted the wp all import team and they gave me half of the code but i can’t figure out the rest Here is what i have and tried: This is my code :

<?php
function do_not_update_if_draft($post_id, $data, $import_id)
{
    // Check for your import
    if ($import_id == 5) {
        // Check if product is draft
        if ( get_post_status ( $ID ) == 'draft' )
            return false;  
        }
        else {
            return true;
    }
}
add_filter('wp_all_import_is_post_to_update', 'do_not_update_if_draft', 10, 3);
?>

this doesn’t seem to work. they mailed me the following:

"You should be able to get the post status by using the get_post_status function on the $post_id variable, and then storing the result in another variable. You’d then write an if/else statement to check & see if the value in your variable is equal to draft, and return the appropriate value (false if the value is equal to draft, true if it does not equal draft)."

Any ideas how i can make this small problem fixed? Thanks Dieter

The also gave this page as an example: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/wp_all_import_is_post_to_update.php

Hey Dieter, can you please check the markdown reference and format your code accordingly? People would like to help but it's difficult to read stretches of code in plain text.

Dieter Jeanty
Dieter Jeanty
292 Points

hey @davidwyett , i just updated the post so the code is formatted correctly :-)