Code Snippets https://cartflows.com/docs-category/code-snippets/ Thu, 15 May 2025 13:08:06 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://cartflows.com/wp-content/uploads/2020/10/cartflows-logo.svg Code Snippets https://cartflows.com/docs-category/code-snippets/ 32 32 How to Show the Order Summary Open on Mobile Devices https://cartflows.com/docs/how-to-show-the-order-summary-open-on-mobile-devices/ Tue, 11 Oct 2022 12:33:34 +0000 https://cartflows.com/?post_type=docs&p=46384 Starting with CartFlows version 1.9.0, the Modern Checkout templates collapse the order summary by default on mobile devices to create a cleaner and more focused layout.

If you’d prefer the order summary to appear open by default on mobile (while still allowing users to collapse it), you can use the following PHP filter:

add_filter( 'cartflows_show_mobile_order_summary_collapsed', '__return_false' );

You can add this code using the Code Snippets plugin (recommended) or by placing it in your child theme’s functions.php file.

💡 Make sure to select PHP as the snippet type if you’re using the Code Snippets plugin.

For guidance, check out: How to Add Custom Code to WordPress

]]>
How to Enable the Product Tab on Store Checkout https://cartflows.com/docs/enable-product-tab-store-checkout/ Thu, 21 Jul 2022 12:13:07 +0000 https://cartflows.com/?post_type=docs&p=46372 With the release of CartFlows version 1.10.0, we introduced the new Store Checkout feature, which replaces the default WooCommerce checkout and follows a standard, streamlined checkout process.

As part of this transition, the Product tab was removed from the Store Checkout funnel to maintain simplicity and alignment with typical eCommerce flows. However, if you have a unique use case where you want to want the product tab on Store checkout, you can bring back the Product tab by using the following PHP filter:

add_filter( 'cartflows_show_store_checkout_product_tab', '__return_true' );

You can add this code using the Code Snippets plugin (recommended) or by placing it in your child theme’s functions.php file.

💡 Make sure to select PHP as the snippet type if you’re using the Code Snippets plugin.
📘 For help adding custom code, refer to: How to Add Custom Code to WordPress

Important: The Product Options feature does not behave the same way in the Store Checkout due to the structure of the store checkout. Some features may have limitations or may not be supported when the Product tab is enabled.

]]>
VAT Field of WooCommerce EU/UK VAT Compliance (Premium) Plugin is not Displaying https://cartflows.com/docs/vat-field-of-eu-uk-vat-not-displaying/ Tue, 25 May 2021 13:43:34 +0000 https://cartflows.com/?post_type=docs&p=38862 If you’re using the WooCommerce EU/UK VAT Compliance (Premium) plugin by David Anderson and the VAT field is not appearing on your CartFlows Checkout page, this documentation will help you display it correctly.

This plugin adds a VAT number field on the WooCommerce checkout page to support tax compliance for EU and UK customers. However, due to how CartFlows customizes the checkout fields, the VAT field may not display by default.

Ensure VAT Field is Displayed on WooCommerce Checkout

Before checking CartFlows compatibility, make sure the VAT field is visible on the default WooCommerce checkout page. If it’s not displayed there, it won’t appear on CartFlows either.

You can confirm this by temporarily switching to the default WooCommerce checkout page and testing whether the VAT field appears as expected.

Why the Field Might Not Show on CartFlows Checkout

CartFlows customizes the WooCommerce checkout form, including billing and shipping fields, using standard WooCommerce hooks and filters. Because of this, fields added by third-party plugins may not always appear in the intended position.

Fortunately, the WooCommerce EU/UK VAT Compliance (Premium) plugin provides a filter that allows you to change the position of the VAT field.

Add the Filter to Display VAT Field on CartFlows Checkout

Add the following filter to your child theme’s functions.php file:

add_filter( 'wc_eu_vat_number_position', 'eu_change_vat_number_position', 10, 1 ); 

/**
* Function to change the position of VAT field only for the CartFlows checkout page.
* 
* @param $current_page current visited page
* @return $current_page current page.
*/
function eu_change_vat_number_position( $position ){

  /* Get global post object */
	global $post;

	/* Get current post type */
	$post_type = get_post_type();
	
	/* Check the current type of the page */
	$is_checkout = get_post_meta( $post->ID, 'wcf-step-type', true );
		
	/* Change position only of the CartFlows checkout page */
	if( 'cartflows_step' == $post_type && 'checkout' === $is_checkout){
		$position = 'woocommerce_after_order_notes';
	}

  return $position;

}

💡 Need help adding custom code? Here’s how to safely add custom snippets to your site.

After adding this filter, the VAT field will display on your CartFlows checkout page in the correct position. If you’ve followed the steps and the field still doesn’t appear, double-check your plugin settings and ensure the field is visible on the standard WooCommerce checkout.

]]>
How to Change the “Choose A variation” text? https://cartflows.com/docs/change-variation-text/ Thu, 30 Jul 2020 08:04:05 +0000 https://cartflows.com/?post_type=docs&p=32997 In some cases, there might be a need to change the Popup Variation Toggler text so that you can match it with your website theme or the product that you are selling from the Checkout or to grab the attention of the users. 

As there is no option in the backend setting to change this text it does not mean that you cannot change it. You can!!. But using the filter that we have provided.

It is very simple to change the text using the filter you just need to copy-paste the code into your child theme’s functions.php file and change the text as per your requirement.

add_filter( 'cartflows_variation_popup_toggle_text', 'change_variation_toggle_text', 10, 1 );

/**
 * Change Choose a variation text.
 *
 * @return text.
 */
function change_variation_toggle_text( $text ) {

	return "Add your choice of text here";
}

Note: Add the above filter to your child theme’s functions.php, here’s an article to help you Add Custom code.

]]>
How to Allow Cache Plugins to Cache the CartFlows Pages? https://cartflows.com/docs/allow-cache-plugins-to-cache-cartflows-pages/ Thu, 30 Jul 2020 08:01:45 +0000 https://cartflows.com/?post_type=docs&p=32995 By default, CartFlows prevents its pages from being cached by common caching plugins. This is done to avoid potential conflicts and ensure that funnel steps work correctly out of the box.

However, if you understand the implications and want to allow caching on CartFlows pages for performance reasons, this documentation explains how to do it.

Why CartFlows Pages Are Not Cached

CartFlows includes special constants in its code that instruct caching plugins to skip its pages:

  • DONOTCACHEPAGE
  • DONOTCACHEOBJECT
  • DONOTCACHEDB

Many popular caching plugins look for these constants, and when detected, they automatically exclude the page from being cached.

How to Allow Caching for CartFlows Pages

You can disable this restriction by using a filter provided by CartFlows. This filter allows you to override the default behavior and selectively allow caching for specific step pages.

Add This Filter to Your Child Theme

To allow caching, add the following code to your child theme’s functions.php file:

add_filter( 'cartflows_do_not_cache_step', 'cache_CartFlows_pages' );

function cache_CartFlows_pages( $post_id ) {
 
// If you want to remove more pages from the cache then add those page's id in the array.

	if( in_array( $post_id , array( 'add_your_landing_page_ids_comma_separated_id_more_than_one' ) ) ){
		return false; // Cache the Pages.
	}

	return true; // Do Not cache.
}

You can find your step page IDs by going to CartFlows > Funnels, opening the Funnel, then hovering over the Step name to view the ID in the URL.

Step ID

In the screenshot above, the Step ID is 68.

How to Add Custom Code Safely

If you’re not sure how to add code to your functions.php file, follow this guide: How to Add Custom Code to WordPress

]]>
How to Turn Off the Auto-fill of Checkout Fields? https://cartflows.com/docs/turn-off-auto-fill-checkout-fields/ Fri, 10 Jul 2020 10:36:30 +0000 https://cartflows.com/?post_type=docs&p=32887 You might be wondering how your billing information is getting pre-filled on the checkout page. Well, let me reveal this trick with you.

When you visit the checkout page and fill-out the billing or shipping information of the checkout fields. Just after filling out all the data, CartFlows automatically stores that information on your local system only. That means this data cannot be displayed unless and until some other user logins to your system and opens the checkout page.

This data is never transferred or stored on the server-side. This is stored just to provide ease of access to the end-users while placing the order next time or multiple times. This reduces the time re-entering that same data again and again. Instead, it will auto-filled from the locally stored data avoiding re-work.

There might be some cases in which you wish to disable this feature on your website and for the same we have provided the following filter –

/**
 * Filter to enable/disable the auto-fill of checkout fields 
 *
 * @param  string $allow having yes/no
 * @return string $allow yes or no
 */
add_filter( 'cartflows_allow_persistence', 'do_not_store_persistance_data', 10, 1 );

function do_not_store_persistance_data( $allow ){
	$allow = 'no';
	return $allow;
}

Note: Add the above filter to your child theme’s functions.php, here’s an article to help you Add Custom code.

]]>
How to Enable the Theme’s Scripts & Styles without Changing the Page Template? https://cartflows.com/docs/enable-themes-style-for-existing-layout/ Fri, 10 Jul 2020 10:34:39 +0000 https://cartflows.com/?post_type=docs&p=32873 You may be looking for an answer as to why are your CartFlows pages do not display your theme’s Header & Footer?

Well, there’s the following reason behind it –

From the beginning, when the CartFlows plugin was released, we intentionally didn’t load the theme’s Header & Footer on the CartFlows pages to avoid any unnecessary conflict with the CartFlows pages. And to ensure more flexibility in design as well as in the creation of distraction-free funnel pages.

Note: If you want to add your theme’s header & footer on the CartFlows pages then you need to change the page template to default. Refer to this article.

But you must be thinking why you need to change the page template if you want to add the theme’s headers and footer on the CartFlows pages. Well, that is the default way and the correct way to add the theme’s header footer. 

But in some cases, your page is displaying the header & footer in distorted format i:e without the CSS while you are not using the “Default” page template so, you want to either remove it or display in proper format then, you can use the following filter to load the theme’s styles & scripts.

This filters can also be used in those cases, where you just want to load the theme’s styles & scripts on the CartFlows pages.

/**
 * Filter to load theme's styles & scripts. 
 *
 * @param  bool $remove_styles true/false
 * @return bool $remove_styles true/false
 */

add_filter( 'cartflows_remove_theme_styles', 'wcf_load_theme_files', 10, 1 );
add_filter( 'cartflows_remove_theme_scripts', 'wcf_load_theme_files', 10, 1 );

function wcf_load_theme_files( $remove_styles ){
	
	$remove_styles = false;

	return $remove_styles;
}

Note: Add the above filter to your child theme’s functions.php, here’s an article to help you Add Custom code.

]]>
How to Turn Off the Auto-fill of Address Fields on Entering Zip-Code? https://cartflows.com/docs/turn-off-auto-fill-address-fields/ Fri, 10 Jul 2020 10:17:44 +0000 https://cartflows.com/?post_type=docs&p=32870 You might be wondering why your Country, State & City fields are getting automatically filled with the proper data when you enter the zip code on your checkout page. Well, it’s not magic, it’s a feature. 

We have integrated the “Zippopotam” library API in the CartFlows which automatically search for the Country, State & City associated with the zip code that you have just entered on the checkout page. 

If the data is found for respective ZIP code then it will be fetched and auto-filled on the checkout page of the CartFlows automatically. 

There might be some cases where you might want to disable this feature and for that, we have provided the following WordPress Filter –

/**
 * Filter to enable/disable the address auto-fill using the zip code. 
 *
 * @param  string $allow having yes/no
 * @return string $allow yes or no
 */

add_filter( 'cartflows_autocomplete_zip_data', 'wa_disable_autocomplete_zipcode', 10, 1 );

function wa_disable_autocomplete_zipcode( $allow ) {
    $allow = 'no';
    return $allow;
}

Note: Add the above filter to your child theme’s functions.php, here’s an article to help you Add Custom code.

]]>