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.