0

I've a problem with one of my WooCommerce functions. This is the function:

add_action( 'woocommerce_checkout_order_processed', 'create_order_pending_notification' );
function create_order_pending_notification( $order_id ) {
    create_notification();
}

So when the user presses the checkout button, the hook get's fired and an order creation notification get's fired. If he cancel now the payment, PayPal redirects the user back to the checkout. If he press now the checkout button again, the same notification get's created twice.

So do you have any idea to prevent that the notification get's created just during the initial pay now button click?

2 Answers 2

3
add_action( 'woocommerce_new_order', 'create_order_pending_notification' );
function create_order_pending_notification( $order_id ) {
    create_notification();
}
0

I'm introducing "The Payment Counter":

add_action( 'woocommerce_checkout_order_processed', 'create_order_pending_notification' );
function create_order_pending_notification( $order_id ) {
    $payment_counter = (int) get_post_meta( $order_id, 'payment_counter', true );
    if ( empty( $payment_counter ) ) {
        update_post_meta( $order_id, 'payment_counter', 1 );
        create_notification();
    } else {
        update_post_meta( $order_id, 'payment_counter', ++ $payment_counter );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.