Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'template_redirect', 'bdev_redirection_after_payment');
- function bdev_redirection_after_payment(){
- if ( is_wc_endpoint_url( 'order-received' ) ) {
- global $wp;
- $order_id = intval( str_replace( 'checkout/order-received/', '', $wp->request ) );
- $order = wc_get_order( $order_id );
- if( $order->has_status( 'failed' ) ) return;
- $product_id_url_paths = array(
- '27' => '/test',
- '28' => '/test-two',
- );
- foreach( $order->get_items() as $item_id => $item_values ){
- $product_id = $item_values->get_product_id();
- foreach( $product_id_url_paths as $key_id => $url_path ){
- if( $key_id == $product_id ){
- wp_redirect( home_url( $url_path ) );
- exit();
- }}}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement