Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 65051

[CartFlows] Thank you page dynamic button page redirecting

$
0
0

Replies: 0

I tried to do a logic like depending on the product the user bought, the button in thank you page directs the user to different pages. There is only one product the user can buy at one time. But the following code is not working, I don’t know why.
Need some help.


add_action( 'woocommerce_thankyou', 'thank_you_button_link');

function thank_you_button_link() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
			$('button#thankyoubutton').onclick(function(){
			  global $woocommerce, $post;
			  $order = new WC_Order($post->ID);
			  foreach ( $order->get_items() as $item_id => $item ) {
   				$product_id = $item->get_product_id();
			  }
			  if ($product_id == 21)) {
             wp_redirect('1');
				  exit();
          }else{
				  wp_redirect('2');
				  exit();
			  }
			});
			  
		  });
    </script>
    <?php
}

Viewing all articles
Browse latest Browse all 65051

Trending Articles