How to Automatically Update WooCommerc...
This WooCommerce code snippet automatically updates cart quantities, eliminating the ...

WPCodeBox
804
Optimize your WP All Import with custom post dates to accurately order imported items from your CSV/XML file, ensuring they display exactly as imported.
<?php
if ( ! function_exists( 'wpcb_set_imported_item_date' ) && ! function_exists( 'wpcb_reset_imported_item_date' ) ) {
function wpcb_set_imported_item_date( $id ) {
if ( $post = get_post( $id ) ) {
$date = get_option( 'my_custom_date_option', date( "Y-m-d H:i:s", time() ) );
if ( $date_obj = new DateTime( $date ) ) {
$date_obj->modify( '-1 second' );
$new_date = $date_obj->format( 'Y-m-d H:i:s' );
update_option( 'my_custom_date_option', $new_date );
wp_update_post( array(
'ID' => $id,
'post_date' => $new_date,
'post_date_gmt' => get_gmt_from_date( $new_date )
) );
}
}
}
function wpcb_reset_imported_item_date( $import_id ) {
delete_option( 'my_custom_date_option' );
}
}
add_action( 'pmxi_saved_post', 'wpcb_set_imported_item_date', 10, 1 );
add_action( 'pmxi_after_xml_import', 'wpcb_reset_imported_item_date', 10, 1 );





