• Resolved Richard Bakos

    (@resonancedesigns)


    Here is the scenario:

    The site is a record shop with a physical store front that deals in new and used inventory. Priority over the inventory must be given to foot-traffic.

    How can one automate a future publish date when woocommerce syncs new inventory from square? We need to put a one month gap between when a product is synced and when it is published. Is this possible with this plugin alone?

    I searched thoroughly for an answer but couldn’t even find anyone asking anything similar.

    • This topic was modified 5 years, 4 months ago by Richard Bakos.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Grigorij S. a11n

    (@grigaswp)

    Hi there,

    Thank you for reaching out!

    With Square for WooCommerce there’s no default way to delay publishing for a month after the product is added to Square I’m afraid.

    This would most likely require code customisation.

    If you decide to pursue such functionality and find yourself in need of help with the code – I’d recommend reaching out to a developer, possibly someone from customizations page on WooCommerce.com.

    Thread Starter Richard Bakos

    (@resonancedesigns)

    Well it’s a good opportunity for me to build my own solution. Thanks for letting me know!

    • This reply was modified 5 years, 4 months ago by Richard Bakos.
    Thomas Shellberg

    (@shellbeezy)

    Automattic Happiness Engineer

    Hey @resonancedesigns,

    You might be able to do this non-destructively using a filter:

    woocommerce_square_create_product_data

    This can be used to override the product data created by WooCommerce when a product is imported.

    One of the keys of the $data array which is filtered there is responsible for the catalog visibility of the product:

    $data['catalog_visibility']

    Or $data['status'] and set to “draft”.

    You can use either one to hide the product programmatically.

    Hope that helps!

    Thread Starter Richard Bakos

    (@resonancedesigns)

    That helps A LOT! You set me down the exact right path, Thomas. Thanks!

    Thomas Shellberg

    (@shellbeezy)

    Automattic Happiness Engineer

    @resonancedesigns,

    Happy to help! I’ll mark this resolved.

    Thread Starter Richard Bakos

    (@resonancedesigns)

    I’m back… So I tried this, and it works to set certain post statuses and product visibility but there is no way to set a date with that filter. Ideally I want to set the post status to ‘future’ and then set a future date so the product will automatically be scheduled to go live on the site on that date…. Here is the simplest approach I tried in my functions.php file:

    function square_sync_delay( $data ) {
    	$data['status'] = 'future';
    	$data['date'] = '2020-02-23 18:57:33';
    	return $data;
    }
    add_filter('woocommerce_square_create_product_data', 'square_sync_delay');

    Products still sync using that, nothing breaks, but it doesn’t take the date and the status defaults to ‘draft’ since the date isn’t being set in the future…

    I was able to get this to work exactly how I want, but only in a DESTRUCTIVE manner by adding to the plugins /includes/Sync/Product_Import.php file:

    $new_product = [
        'post_title'   => wc_clean( $data['title'] ),
        'post_status'  => isset( $data['status'] ) ? wc_clean( $data['status'] ) : 'future', // RD: Changed from 'publish' to 'future' - MAKE DYNAMIC
        'post_type'    => 'product',
        'post_date'    => '2020-02-23 18:57:33', // RD: Added date customization - MAKE DYNAMIC
        'post_content' => isset( $data['description'] ) ? $post_content : '',
        'post_author'  => get_current_user_id(),
        'menu_order'   => isset( $data['menu_order'] ) ? (int) $data['menu_order'] : 0,
    ];

    The comments in the code explain what I changed/added. By default, the plugins product constructor code sinppet I modified doesn’t specify ‘post_date’ so it uses the WP default of the current date and time. With it modified like this though, it works just as I would expect and want it to.

    In addition to this I would also love to make the ‘post_date’ and ‘post_status’ data dynamic and put options for them in the admin woocommerce-square settings for “Publish Settings” where admins can pick the default post status for synced products from a dropdown (published, draft, future) as well as date presets with options like “1 Week from Sync”, “1 Month from Sync”, “3 Months from Sync” etc…

    I would love a way to either A) At least be able to do this from my theme. Or B) See this in a future iteration of the plugin.

    Is there a git repo for this plugin that I can fork? I’ve already started building this myself and am willing to maintain my own modified branch of the plugin just so I can have this feature.

    If there is in fact a way I can do this in my theme using that filter or perhaps a combination of some things, and I am just missing something, please clue me in… but I really think it’d be a nice thing to bake into the plugin itself.

    • This reply was modified 5 years, 2 months ago by Richard Bakos.
    Thread Starter Richard Bakos

    (@resonancedesigns)

    Another way to go about this just occurred to me… Could the plugin be told to check the date for inventory items in Square as it’s looping though them, BEFORE it imports them into the WP database? … some kind of if statement that only imports records that are at least a month old? As well as addressing the root issue, an option like this would also help to reduce unnecessarily used database storage and resources.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Future Publish Date of Syncs’ is closed to new replies.