Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. add_action( 'template_redirect', 'bdev_redirection_after_payment');
  2. function bdev_redirection_after_payment(){
  3.  
  4. if ( is_wc_endpoint_url( 'order-received' ) ) {
  5. global $wp;
  6. $order_id = intval( str_replace( 'checkout/order-received/', '', $wp->request ) );
  7. $order = wc_get_order( $order_id );
  8. if( $order->has_status( 'failed' ) ) return;
  9. $product_id_url_paths = array(
  10. '27' => '/test',
  11. '28' => '/test-two',
  12. );
  13.  
  14. foreach( $order->get_items() as $item_id => $item_values ){
  15. $product_id = $item_values->get_product_id();
  16. foreach( $product_id_url_paths as $key_id => $url_path ){
  17. if( $key_id == $product_id ){
  18. wp_redirect( home_url( $url_path ) );
  19. exit();
  20. }}}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement