Answers for "Disable “woocommerce_thankyou” Action if WooCommerce Order Failed"

0

Disable “woocommerce_thankyou” Action if WooCommerce Order Failed

/**
 * @snippet       Remove "woocommerce_thankyou" Action if Order Fails - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.9
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
add_action( 'wp_head', 'bbloomer_tracking_exclude_failed_orders' );
  
function bbloomer_tracking_exclude_failed_orders() {
   global $wp;
   // ONLY RUN ON THANK YOU PAGE
   if ( ! is_wc_endpoint_url( 'order-received' ) ) return; 
   // GET ORDER ID FROM URL
   $order_id = absint( $wp->query_vars['order-received'] );
   $order = wc_get_order( $order_id );
   if ( $order->has_status( 'failed' ) ) {
      // DISABLE ANY FUNCTION HOOKED TO "woocommerce_thankyou"
      remove_all_actions( 'woocommerce_thankyou' );
   }
}
Posted by: Guest on July-30-2021

Code answers related to "Disable “woocommerce_thankyou” Action if WooCommerce Order Failed"

Browse Popular Code Answers by Language