CartFlows overwrites some WooCommerce templates and here is how you can overwrite them

Recently, I got a request to add additional text under the product name on the checkout page. It seemed an easy job. All I had to do was create a file at woocommerce/checkout/review-order.php in, the active theme’s directory. But it didn’t work. Because the CartFlow plugin was overwriting some WooCommerce templates.

List of WooCommerce templates that CartFlow plugin overwrites :

  • Cart
    • cart/cart-shipping.php
  • Checkout
    • checkout/form-billing.php
    • checkout/form-checkout.php
    • checkout/form-coupon.php
    • checkout/form-login.php
    • checkout/form-shipping.php
    • checkout/payment.php
    • checkout/payment-method.php
    • checkout/review-order.php
    • checkout/thankyou.php
  • Global
    • global/form-login.php
  • Notices
    • notices/error.php
    • notices/notice.php
    • notices/success.php
  • Order
    • order/order-details.php

Now, all we have to do is use, “woocommerce_locate_template” filter to force woocommerce to use our custom defined templates, instead of the templates defined in CartFlow.

Here is the code snippet to overwrite CartFlow templates :

// source : 

add_filter( 'woocommerce_locate_template', 'wptips_locate_template', 21, 3 );

function wptips_locate_template( $template, $template_name, $template_path ){

	global $woocommerce;
		$_template = $template;

		if ( ! $template_path ) {
			$template_path = $woocommerce->template_url;

        //You can change this Path to match your plugin or theme , where you have defined custom woocommerce templates.
		$my_woocommerce_template_path = get_bloginfo('stylesheet_directory') . '/woocommerce/';  
		$template    = locate_template(
				$template_path . $template_name,
		// Get the template from the active theme, if it exists
		if ( ! $template && file_exists( $my_woocommerce_template_path . $template_name ) ) {
			$template = $my_woocommerce_template_path . $template_name;
		// Use default template
		if ( ! $template ) {
			$template = $_template;
		// Return what we found
		return $template;

You can implement the above code in your theme’s functions.php file, and it will force WooCommerce to use the templates defined in your active theme.

Feel free to comment here, if you have any questions. I would love to help you out. 🙂

By Murali Kumar

I am a Full Stack Web Developer with over 12 years of experience. I love WordPress & WooCommerce.

If you need the help from a WordPress developer for your website, get in touch now!.

Twitter : @geekz
YouTube : @wptipsofficial

Leave a Reply

Your email address will not be published. Required fields are marked *