How to Override V3 Layout product templates in AMP.

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 “wc_get_template” filter to override the product templates of WooCommerce at a priority of 10 so by using the same filter “wc_get_template” you can override our templates in the amp but you have to use the priority of the filter higher than 10 to override.

add_filter('wc_get_template','ampforwp_woocommerce_template_override',10,5);

Below is an example of how to override a template.

let’s override the quantity-input template using a custom plugin or you can do it in your theme functions.php file.

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;

add_filter('wc_get_template','override_ampwcpro_woocommerce_templates',20,5);


function override_ampwcpro_woocommerce_templates($template, $template_name, $args, $template_path, $default_path){
  if($template_name == 'global/quantity-input.php'){
	  $template = plugin_dir_path(__FILE__).'custom_template/quantity-input.php';
	 }
   return $template;

}

As you can see in the above code we have added a filter with priority 20 which is higher than 10 to override.

And in the function, as we are overriding quantity-input file so we are checking that and then giving the customized template path.

If you want to download the above example custom plugin Click Here.

Before overriding the quantity-input template in AMP

The output after overriding quantity-input template in AMP

That’s it for this tutorial!

We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.

Share
Published by
Sonali R

How to create an AWeber form in AMP

If you want to add an AWeber form in AMP then first you need to…

3 years ago

How to setup webpushr notification in AMP

Webpushr is the fastest growing web push notifications platform that marketers love & developers rely…

3 years ago

How to add Adobe Analytics in AMP

Follow these steps to add Adobe Analytics in AMP Step 1: Go to WordPress Admin Area -> AMP…

3 years ago

What is the CWV plugin all about

Core Web Vitals are the subset of Web Vitals that apply to all web pages,…

4 years ago

How to fix “Alternate page with proper canonical tag” Page Index issue in Google Search Console

The following reasons can be shown for non-indexing. Server error (5xx) Your server returned a 500-level…

4 years ago

Google Analytics ( GA4 ) integration in AMPforWP

We have added the Google Analytics 4 ( GA 4 ) integration in AMPforWP v1.0.80.…

4 years ago