I found that Woocommerce is disabling autosave, maybe for good reason, but I’d like to have it turned on and see if it presents an issue. This is what I found in the __construct in their post type class, from wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php….
// Disable Auto Save
add_action( 'admin_print_scripts', array( $this, 'disable_autosave' ) );
Then further down I see this function….
/**
* Disable the auto-save functionality for Orders.
*/
public function disable_autosave() {
global $post;
if ( $post && in_array( get_post_type( $post->ID ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
wp_dequeue_script( 'autosave' );
}
}
I tried commenting out the wp_dequeue_script call above just to test if that script was enqueued would it work and still does not autosave. But I’d rather not as it is in the core Woocommerce and subject to updates. How can I re-enable without altering the plugin? Or does anyone have any experience as to why I should not?
The way I am testing is by adding this to the save_post hook:
add_action( 'save_post', 'save_product_meta' );
function save_product_meta( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
error_log("DOING AUTOSAVE for " . $post_id);
return $post_id;
}
In WordPress admin, I get the log entry while letting a normal post sit on screen without saving, but not when a shop_order type post is created.