Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @kingswp

    Good to know that your main concern is resolved and here is the information for your follow-up query.

    One follow-up question I have is, in my case “woocommerce_payment_complete” hook got triggered only once i.e., after successful payment and order status is ‘completed’. Will this always be the case as I see @smbhatia03 mention that “but before the hook applies, WooCommerce is going to change the order status either to processing or completed”?
    Does it mean “woocommerce_payment_complete” hook might be triggered twice – once when the order status is “processing” and once when order status “completed”? How can I simulate for order status status is “processing” to ensure I have covered this case as well?

    Following hook “woocommerce_payment_complete” is fired only when the payment is completed if an order has one of the following order status on-holdpendingfailedcancelled.

    For the filter point which you are asking, “woocommerce_payment_complete_order_status” filter is used to Change the order status when the payment is completed.

    Hello @eclecticvins

    Can you just confirm once, that Shop and other pages are selected in the WooCommerce settings.

    Go to:
    WooCommerce > Settings > Products (Tab)
    Fields : Shop page

    WooCommerce > Settings > Advanced (Tab)
    Fields : Cart page, Checkout page, My account page, Terms and conditions

    I hope you find this information useful! If you have any more queries or need further help, don’t hesitate to ask.

    Hello @iam3ple

    Here is the solution for your query. Following filter is used to change/customize the Add to cart message.

    "wc_add_to_cart_message_html"

    Following code will add “Proceed to checkout” button link next to “View cart” in the notice when the product is successfully added to cart.

    function wc_add_to_cart_message_html_custom_fun( $message, $products, $show_qty ) {
    	return '<a href="'.esc_url( wc_get_checkout_url() ).'" tabindex="1" class="button wc-forward">'.esc_html__( 'Proceed to checkout', 'woocommerce' ).'</a> '. $message;
    }
    add_filter('wc_add_to_cart_message_html', 'wc_add_to_cart_message_html_custom_fun', 10, 3);

    Add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code Snippets plugin. Remember, it’s not advisable to add custom code directly to your parent theme’s functions.php file, as updates to the theme will erase it.

    I hope you find this information useful! If you have any more queries or need further help, don’t hesitate to ask.

    Hello @kingswp

    There are three different WooCommerce hooks after payment completed, I would like to talk about.

    1. woocommerce_pre_payment_complete
    2. woocommerce_payment_complete
    3. woocommerce_payment_complete_order_status_$status

    All of those hooks are fired when an order is either paid or doesn’t require a payment (Cash on Delivery for example). They also apply for custom payment gateways.

    1. woocommerce_pre_payment_complete

    woocommerce_pre_payment_complete applies at the very beginning and doesn’t depend on order status.

    add_action( 'woocommerce_pre_payment_complete', 'woocommerce_pre_payment_complete_custom_fun' );
    
    function woocommerce_pre_payment_complete_custom_fun( $order_id ) {
    	$order = wc_get_order( $order_id );
    	// get the order data and do anything
    }

    You can get a lot of information from the $order object, like $order->get_items() to get order items or $order->get_payment_method() to get a payment method slug or $order->get_user_id() to get a customer ID.

    2. woocommerce_payment_complete

    woocommerce_payment_complete will be fired only if an order has one of the following order status on-hold, pending, failed, cancelled, but please keep in mind that this list of statuses can also be filtered with woocommerce_valid_order_statuses_for_payment_complete.

    But before the hook applies, WooCommerce is going to change the order status either to processing or completed, which also can be filtered with woocommerce_payment_complete_order_status.

    add_action( 'woocommerce_payment_complete', 'woocommerce_payment_complete_custom_fun' );
    
    function woocommerce_payment_complete_custom_fun( $order_id ) {
    	$order = wc_get_order( $order_id );
    	// get the order data and do anything
    }

    3. woocommerce_payment_complete_order_status

    woocommerce_payment_complete_order_status_$status will be fired for the rest of the order statuses.

    add_action( 'woocommerce_payment_complete_order_status_processing', 'rudr_complete_for_status' );
    add_action( 'woocommerce_payment_complete_order_status_completed', 'rudr_complete_for_status' );
    
    function rudr_complete_for_status( $order_id ){
    	$order = wc_get_order( $order_id );
    	// get the order data and do anything
    }

    I hope you find this information useful! If you have any more queries or need further help, don’t hesitate to ask.

    Hello @turbodogma
    If you could help with site details, so can check and provide you the fix.

Viewing 5 replies - 1 through 5 (of 5 total)