Skip to content
Advertisement

How to target all pages except WooCommerce Thankyou page

I have a hook that looks like this:

add_action( 'woocommerce_thankyou', 'thank_you_page', 90, 1 );
function thank_you_page( $order_id ) {
  //target woocommerce thank you page.
}

This works well, however I now need the opposite. All pages that don’t use this hook…

Can I embed the above into an IF statement and then use the ELSE statement to resolve?

Advertisement

Answer

As the hook woocommerce_thankyou is triggered in WooCommerce “Order received” page, To target all pages except WooCommerce Thankyou “Order received” page, You will use the following condition inside any function or template:

if( ! ( is_checkout() && is_wc_endpoint_url('order-received') ) ) {
     echo '<p>' . __("Not Thankyou page") . '</p>';
}

So to target “Order received” Thankyou page you will use:

if( is_checkout() && is_wc_endpoint_url('order-received') ) {
     echo '<p>' . __("This is Thankyou page") . '</p>';
}

Related: WooCommerce Conditional Tags

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement