Found this, which combined with datepicker seems to work.
woocommerce_admin_order_data_after_order_details
Any other suggestions/possibilities?
Hello @kabouton ,
Out of the box, WooCommerce does not include a feature that can allow change only the date paid option in the order.
The hook you have found seems to be the correct way to make the changes.
I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.
You can also visit the WooCommerce Facebook group or the #developers
channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.
Thank you 🙂
Hi there,
We’ve not heard back from you in a while, so I’m marking this thread as resolved.
Hopefully, you were able to find a solution to your problem! If you have further questions, please feel free to open a new topic.
Thank you 🙂
Howdy @kabouton,
Would you mind posting the full code to your solution you used with the datepicker and the hook (woocommerce_admin_order_data_after_order_details)?
Thanks,
Tim
This works for me. Good luck
add_action( 'woocommerce_admin_order_data_after_order_details', 'sample_after_order_fn' );
function sample_after_order_fn( $order ){
$date_completed_ts = get_post_meta( $order->get_id(), '_date_completed', true ); //timestamp
$formatted_date = $date_completed_ts ? date('Y-m-d H:i:s', $date_completed_ts+( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )) : 'Not completed';
?>
<br class="clear" />
<h4>Update Date Paid <a href="#" class="edit_address">Edit</a></h4>
<div class="address">
<p<?php if( empty( $date_paid ) ) echo ' class="none_set"' ?>>
<strong>Date Paid:</strong><?php echo $formatted_date; ?>
</p>
</div>
<div class="edit_address">
<?php
woocommerce_wp_text_input( array(
'id' => '_date_paid',
'label' => 'Date Paid:',
'placeholder'=> 'YYYY-MM-DD',
'wrapper_class'=> 'form-field-wide',
'class' => 'date-picker',
'style' => 'width: 100%',
'description' => 'The day payment was made.'
)
);
?></div><?php
}
add_action( 'woocommerce_process_shop_order_meta', 'sample_save', 45, 2 ); // 45 sets it so run after order data saved
function sample_save( $order_id, $post ){
$order = wc_get_order( $order_id );
$newStatus = wc_clean( $_POST[ 'order_status' ] );
$oldStatus = wc_clean( $_POST[ 'original_post_status' ] );
$newDatePaid = wc_clean( $_POST[ '_date_paid' ] );
$datePaid = $newDatePaid ? $newDatePaid : '';
// LOAD THE WC LOGGER
$logger = wc_get_logger();
if( $order ){
if ( in_array( $oldStatus, array('wc-on-hold', 'wc-processing', 'wc-completed') ) && $newStatus == 'wc-pending' ) {
$order->set_date_paid(null);
$order->set_date_completed($null);
$logger->info( "Status is now pending so set paid date to null", array( 'source' => 'gk3-testing' ) );
}
if ( $datePaid && $newStatus !== 'wc-pending' ) {
$order->set_date_paid($newDatePaid);
$order->set_date_completed($newDatePaid);
$logger->info( "set paid date to new date if not pending", array( 'source' => 'gk3-testing' ) );
}
$order->save();
}
}
Thanks! You are incredible! Do you have a Paypal email address or another way for me to contribute something to you? I would like to give you a little something as a thank you!
Gosh, I’m blushing. Not to worry. I have gotten so much help myself over the forums it’s nice to payitforward. Glad it did the trick.
You are an abundant person, thanks! I do love and appreciate the WordPress world for this reason.