{"id":16069,"date":"2020-02-08T06:56:36","date_gmt":"2020-02-08T06:56:36","guid":{"rendered":"https:\/\/ampforwp.com\/tutorials\/?post_type=ht_kb&#038;p=16069"},"modified":"2020-02-08T07:08:59","modified_gmt":"2020-02-08T07:08:59","slug":"how-to-overridev3-layout-product-templates-in-amp","status":"publish","type":"ht_kb","link":"https:\/\/ampforwp.com\/tutorials\/article\/how-to-overridev3-layout-product-templates-in-amp\/","title":{"rendered":"How to Override V3 Layout product templates in AMP."},"content":{"rendered":"\n<p>If you are trying to override specific product templates of AMP Woocommerce Pro plugin then you need to follow these below instructions.  <br><\/p>\n\n\n\n<p>In Amp WooCommerce Pro plugin we are using  &#8220;<strong>wc_get_template<\/strong>&#8221; filter to override the product templates of WooCommerce at a <strong>priority of 10<\/strong> so by using the same filter &#8220;<strong>wc_get_template<\/strong>&#8221; you can override our templates in the amp but you have to use the priority of the filter <strong>higher than 10<\/strong> to override.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">add_filter('wc_get_template','ampforwp_woocommerce_template_override',10,5);<\/pre>\n\n\n\n<p><strong>Below is an example of how to override a template. <\/strong><\/p>\n\n\n\n<p> let&#8217;s override the quantity-input template using a custom plugin or you can do it in your theme functions.php file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ Exit if accessed directly.\nif ( ! defined( 'ABSPATH' ) ) exit;\n\nadd_filter('wc_get_template','override_ampwcpro_woocommerce_templates',20,5);\n\n\nfunction override_ampwcpro_woocommerce_templates($template, $template_name, $args, $template_path, $default_path){\n  if($template_name == 'global\/quantity-input.php'){\n\t  $template = plugin_dir_path(__FILE__).'custom_template\/quantity-input.php';\n\t }\n   return $template;\n\n}\n<\/pre>\n\n\n\n<p>As you can see in the above code we have added a filter with priority 20 which is higher than 10 to override.<\/p>\n\n\n\n<p>And in the function, as we are overriding quantity-input file so we are checking that and then giving the customized template path.<\/p>\n\n\n\n<p>If you want to download the above example custom plugin <strong><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/amp_override_product_templates.zip\">Click Here<\/a><\/strong>.<\/p>\n\n\n\n<h4><strong>Before overriding the quantity-input template in AMP<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"502\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/17-1024x502.png\" alt=\"\" class=\"wp-image-16149\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/17.png 1024w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/17-300x147.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/17-768x377.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/17-50x25.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/17-60x29.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/17-100x49.png 100w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4>The output after overriding <strong>quantity-input template<\/strong> in AMP<\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"517\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1-1024x517.png\" alt=\"\" class=\"wp-image-16078\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1-1024x517.png 1024w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1-300x152.png 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1-768x388.png 768w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1-50x25.png 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1-60x30.png 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1-100x51.png 100w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2020\/02\/4-1.png 1045w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>That\u2019s it for this tutorial!<\/strong><\/p>\n\n\n\n<p>We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.<\/p>\n<div id=\"div-1\" class=\"hkb-feedback\">\n\t\t\t<strong class=\"ht-mobile-exit__title\">Ask your Questions Directly!<\/strong><br>\n\t\t\t<div class=\"hkb_widget_exit__content\" style=\"font-size: 14px;\">If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!<\/div>\n\t\t\t<a href=\"https:\/\/ampforwp.com\/support\/#contact\" id=\"button\" target=\"_blank\" rel=\"noopener noreferrer\"><button>Yes, I have a Question<\/button><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>If you are trying to override specific product templates of AMP Woocommerce Pro plugin then you need to follow these below instructions. In Amp WooCommerce Pro plugin we are using &#8220;wc_get_template&#8221; filter to override the product templates of WooCommerce at a priority of 10 so by using the same filter&#8230;<\/p>\n","protected":false},"author":18,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[91],"ht-kb-tag":[],"_links":{"self":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/16069"}],"collection":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/comments?post=16069"}],"version-history":[{"count":28,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/16069\/revisions"}],"predecessor-version":[{"id":16158,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/16069\/revisions\/16158"}],"wp:attachment":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/media?parent=16069"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-category?post=16069"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-tag?post=16069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}