Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Charge a WooCommerce pre-order when the associated order is set to Completed status
<?php // only copy this line if needed
/**
* Charge a WooCommerce pre-order when the associated order is set to Completed status
*
* @param int $order_id
* @param \WC_Order $order
*/
function sv_wc_charge_order_on_order_complete( $order_id, $order ) {
if ( ! class_exists( 'WC_Pre_Orders_Order' ) ) {
return;
}
if ( WC_Pre_Orders_Order::order_contains_pre_order( $order ) && WC_Pre_Orders_Manager::can_pre_order_be_changed_to( 'completed', $order ) ) {
WC_Pre_Orders_Manager::complete_pre_order( $order, $message );
}
}
add_action( 'woocommerce_order_status_completed', 'sv_wc_charge_order_on_order_complete', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.