arie_cristianD

redirect user after checkout post package product

Oct 22nd, 2025
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. add_filter(
  2.     'woocommerce_get_return_url',
  3.     function ( $return_url, $order ) {
  4.         if ( ! $order instanceof WC_Order ) {
  5.             return $return_url;
  6.         }
  7.         if ( ! $order->has_status( array( 'processing', 'completed', 'on-hold' ) ) ) {
  8.             return $return_url;
  9.         }
  10.  
  11.         $redirect_url = home_url( '/account/edit-account/' );
  12.         $target_slug  = 'post_package';
  13.         $match        = false;
  14.  
  15.         foreach ( $order->get_items() as $item ) {
  16.             $product = $item->get_product();
  17.             if ( ! $product ) {
  18.                 continue;
  19.             }
  20.             if ( $product->get_type() === $target_slug ) {
  21.                 $match = true;
  22.                 break;
  23.             }
  24.         }
  25.  
  26.         return $match ? $redirect_url : $return_url;
  27.     },
  28.     10,
  29.     2
  30. );
  31.  
Advertisement
Add Comment
Please, Sign In to add comment