Created
September 13, 2020 05:21
-
-
Save tamarazuk/2419027abde9c85223572a289f84c4bf to your computer and use it in GitHub Desktop.
Charge a WooCommerce pre-order when the associated order is set to Completed status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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