Reputation: 13
I am creating a payment gateway for woocommerce but I am facing an issue that after successful payment I am redirecting to thank you page and my order status is not updating to 'processing' or 'completed'.
I am using woocommerce_thankyou hook in my plugins main file.
add_action( 'woocommerce_thankyou_epg', 'my_change_status_function', 10, 1 );
function my_change_status_function( $order_id ) {
$order = new WC_Order( $order_id );
$order->update_status( 'processing', __( 'Payment received.', 'wc-gateway-offline' ) );
}
Actually in this functions before updating the status I want to send a API call to check the status of the payment and than according to the response I want to update the status of the order.
Can anybody help me in sorting this out.
Upvotes: 0
Views: 6879
Reputation: 6650
Change the hook to:
add_action( 'woocommerce_thankyou', 'my_change_status_function', 20, 1 );
function my_change_status_function( $order_id ) {
$order = new WC_Order( $order_id );
$order_pay_method = get_post_meta( $order->id, '_payment_method', true );
if($order_pay_method == 'epg'){
$order->update_status( 'processing', __( 'Payment received.', 'wc-gateway-offline' ) );
}
}
Corrected the hook.
Upvotes: 2
Reputation: 1078
add_action( 'woocommerce_thankyou', 'my_change_status_function', 10, 1 );
function my_change_status_function( $order_id ) {
$order = new WC_Order( $order_id );
$order->update_status( 'processing', __( 'Payment received.', 'wc-gateway-offline' ) );
}
Upvotes: 0