{"id":2995,"date":"2021-06-19T17:07:05","date_gmt":"2021-06-19T17:07:05","guid":{"rendered":"https:\/\/scriptfeeds.com\/blog\/?p=2995"},"modified":"2023-10-31T21:40:44","modified_gmt":"2023-10-31T21:40:44","slug":"custom-thank-you-page","status":"publish","type":"post","link":"https:\/\/scriptfeeds.com\/blog\/wordpress\/custom-thank-you-page\/","title":{"rendered":"WooCommerce Product specific custom thank you page"},"content":{"rendered":"\n<p>Recently one of our client asked us <strong>If they we can create a specific custom thank you page for a particular product in WooCommerce<\/strong>. It really challenging and interesting for us also. So we started checking with hooks and came up with an solution via few lines of code. So Just follow the below steps to create a Product specific  custom custom thank you page.<\/p>\n\n\n\n<p>You can also use some plugins to achieve this but we as a developer always recommend to use custom code because it never adds extra Javascript, CSS file burden on website.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#steps-to-redirect-to-a-custom-thank-you-page-based-on-product-id-using-hook\">Steps to redirect to a custom thank you page based on product ID using hook<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-medium-font-size\" id=\"steps-to-redirect-to-a-custom-thank-you-page-based-on-product-id-using-hook\"><strong>Steps to redirect to a custom thank you page based on product ID using hook<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to the functions.php file of your child theme. If you don&#8217;t know how to create <strong><a href=\"https:\/\/developer.wordpress.org\/themes\/advanced-topics\/child-themes\/\" data-type=\"link\" data-id=\"https:\/\/developer.wordpress.org\/themes\/advanced-topics\/child-themes\/\" target=\"_blank\" rel=\"noopener\">child theme<\/a><\/strong>, Just follow steps here.<\/li>\n\n\n\n<li>Copy the below code and Paste it in functions.php file.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\nadd_action( 'woocommerce_thankyou', 'redirect_product_based', 1 ); \nfunction redirect_product_based ( $order_id ){\n            $order = wc_get_order( $order_id );\n        \n            foreach( $order-&gt;get_items() as $item ) {\n                \/\/ Add your product id below\n                if ( $item&#91;'product_id'] == 643 ) {\n                    \/\/ change URL that you want to send your customer to\n                     wp_redirect( 'http:\/\/example.com\/custom-thank-you\/' );\n                \n                }\n            }        \n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Replace the [&#8216;product_id&#8217;] with your product id and url with your thank you page url.<\/li>\n\n\n\n<li>Save the file and check the process by making a checkout process.<\/li>\n<\/ul>\n\n\n\n<p>Might be you thinking how to get the product id? Well to get the product\/subscription id of WooCommerce product, just open the product edit page in backend and copy the number from URL of product edit page (Check image below) or just place your cursor on any product in &#8220;All Product&#8221; list of WooCommerce and it will show the Product ID in light green shade.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"646\" height=\"64\" src=\"https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2021\/06\/custom-checkout-page.jpeg\" alt=\"custom thank you\" class=\"wp-image-4141\" srcset=\"https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2021\/06\/custom-checkout-page.jpeg 646w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2021\/06\/custom-checkout-page-300x30.jpeg 300w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2021\/06\/custom-checkout-page-150x15.jpeg 150w, https:\/\/scriptfeeds.com\/blog\/wp-content\/uploads\/2021\/06\/custom-checkout-page-399x40.jpeg 399w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/figure>\n\n\n\n<p>So that&#8217;s all you have to do to <strong>Show different Thank You page for specific product or product attribute<\/strong>. <strong><a href=\"https:\/\/scriptfeeds.com\/blog\/hire-us\/\" data-type=\"page\" data-id=\"3537\">Click here if you need any help regarding WordPress.<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently one of our client asked us If they we can create a specific custom thank you page for a particular product in WooCommerce. It really challenging and interesting for us also. So we started checking with hooks and came up with an solution via few lines of code. So Just follow the below steps [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3393,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jnews-multi-image_gallery":[],"jnews_single_post":{"subtitle":"","format":"standard","video":"","gallery":"","source_name":"","source_url":"","via_name":"","via_url":"","override_template":"0","override":[{"template":"1","single_blog_custom":"","parallax":"1","fullscreen":"1","layout":"right-sidebar","sidebar":"default-sidebar","second_sidebar":"default-sidebar","sticky_sidebar":"1","share_position":"top","share_float_style":"share-monocrhome","show_share_counter":"1","show_view_counter":"1","show_featured":"1","show_post_meta":"1","show_post_author":"1","show_post_author_image":"1","show_post_date":"1","post_date_format":"default","post_date_format_custom":"Y\/m\/d","show_post_category":"1","show_post_reading_time":"0","post_reading_time_wpm":"300","show_zoom_button":"0","zoom_button_out_step":"2","zoom_button_in_step":"3","show_post_tag":"1","show_prev_next_post":"1","show_popup_post":"1","number_popup_post":"1","show_author_box":"0","show_post_related":"0","show_inline_post_related":"0"}],"override_image_size":"0","image_override":[{"single_post_thumbnail_size":"crop-500","single_post_gallery_size":"crop-500"}],"trending_post":"0","trending_post_position":"meta","trending_post_label":"Trending","sponsored_post":"0","sponsored_post_label":"Sponsored by","sponsored_post_name":"","sponsored_post_url":"","sponsored_post_logo_enable":"0","sponsored_post_logo":"","sponsored_post_desc":"","disable_ad":"0"},"jnews_primary_category":{"id":"","hide":""},"footnotes":""},"categories":[75,86],"tags":[111,112,113],"class_list":["post-2995","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","category-woocommerce","tag-custom-checkout-page-without-plugin","tag-product-based-checkout-thank-you-page","tag-woocommerce-custom-checkout-page"],"_links":{"self":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts\/2995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/comments?post=2995"}],"version-history":[{"count":0,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/posts\/2995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/media\/3393"}],"wp:attachment":[{"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/media?parent=2995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/categories?post=2995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scriptfeeds.com\/blog\/wp-json\/wp\/v2\/tags?post=2995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}