Mahbubur Rahman

Thoughts and Writings

11 Jan 2017
How to update WooCommerce sale price dates meta using WPUF date fields

If you are having an issue with updating the schedule dates of WooCommerce product using WPUF fields, you can follow the given instructions to solve this issue.

1) Add two date type field to WPUF form that you created to allow users for uploading products.

2) Insert _sale_price_dates_from & _sale_price_dates_to meta keys accordingly for these two fields.

Refer Screenshot:
http://prntscr.com/du6fqj

3) Change the date format of WPUF date field.

Refer Screenshot:
http://prntscr.com/du66dq

4) Now, add the following code inside the theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
function update_product_schedule_date_meta( $post_id ) {
    $dates_from = get_post_meta( $post_id, '_sale_price_dates_from', true );
    $dates_to = get_post_meta( $post_id, '_sale_price_dates_to', true );

    $dates_from = strtotime($dates_from);
    $dates_to = strtotime($dates_to);

    update_post_meta( $post_id, '_sale_price_dates_from', $dates_from );
    update_post_meta( $post_id, '_sale_price_dates_to', $dates_to );
}

add_action( 'wpuf_add_post_after_insert', 'update_product_schedule_date_meta' );
add_action( 'wpuf_edit_post_after_update', 'update_product_schedule_date_meta' );

All done, add a product from the frontend with the sales price and insert dates for sales from, sales to fields. The fields data will update properly to WooCommerce sale price dates.

Leave a Comment

Your email address will not be published. Required fields are marked *