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 : https://wordpress.org/support/topic/cartflows-overwrites-woocommerce-templates-in-child-theme/ 

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(
			array(
				$template_path . $template_name,
				$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. 🙂