Actions and filters

Along with the customization options available in plugin settings, CartBounty also allows the use of different hooks for advanced customization. These hooks are an excellent way if you are looking to alter or extend the features of CartBounty without modifying the core files of the plugin.

Below you will find a list of hooks available in CartBounty alongside different examples. When using these actions and filters to modify the plugin, please add your code in the functions.php file of your theme.

1. Introduction to hooks

Here is the official WordPress definition of hooks: Hooks are a way for one piece of code to interact/modify another piece of code at specific, pre-defined spots. They make up the foundation for how plugins and themes interact with WordPress Core.

WordPress offers two types of hooks: actions and filters. Actions allow to add additional data or change how plugin or themes operates. Filters provide the ability to alter data during execution of plugins and themes.

2. General hooks

These are general hooks available in CartBounty for various operations like changing phone validation, email address, time after which the abandoned cart is considered to be abandoned etc.

Filters:

  1. cartbounty_pro_from_email
  2. cartbounty_pro_waiting_time
  3. cartbounty_pro_phone_validation
  4. cartbounty_pro_include_tax
  5. cartbounty_pro_recaptcha_minimum_allowed_score
  6. cartbounty_pro_price_format
  7. cartbounty_pro_display_currency_code
  8. cartbounty_pro_coupon_expiry_date_format
  9. cartbounty_pro_unfinished_order_statuses
  10. cartbounty_pro_landing_url
  11. cartbounty_pro_cart_url_utm_tracking
  12. cartbounty_pro_coupon_auto_apply
  13. cartbounty_pro_default_country
  14. cartbounty_pro_international_phone_preferred_countries
  15. cartbounty_pro_display_full_address
  16. cartbounty_pro_custom_product_fields
  17. cartbounty_pro_export_columns
  18. cartbounty_pro_excluded_countries
  19. cartbounty_pro_excluded_languages
  20. cartbounty_pro_minimum_cart_total

Edit “From” email address

Here is an example how to replace the default “From” email that is used for sending notification emails using cartbounty_pro_from_email filter.

function change_from_email( $html ){
	return 'your@email.com';
}
add_filter( 'cartbounty_pro_from_email', 'change_from_email' );

Edit cart abandonment time

Example how to edit the default waiting time after which the cart is considered abandoned from 60 minutes (default time) to 30 minutes using cartbounty_pro_waiting_time filter. Note that the minimum allowed time is 20 minutes.

function change_waiting_time( $minutes ){
	return 30; //Minimum allowed time is 20 minutes
}
add_filter( 'cartbounty_pro_waiting_time', 'change_waiting_time' );

Disable phone validation

Here is an example how to disable the default phone validation of Exit Intent and Early capture popups.

function cartbounty_pro_disable_phone_validation( $regex ){
	return '';
}
add_filter( 'cartbounty_pro_phone_validation', 'cartbounty_pro_disable_phone_validation' );

Edit phone validation

Example how to change phone number validation RegEx that will allow only US phone numbers with area code (i.e., 111-222-3333, or 111.222.3333, or (111) 222-3333, or 1112223333, etc.).

function cartbounty_pro_change_phone_validation( $regex ){
	return '^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$';
}
add_filter( 'cartbounty_pro_phone_validation', 'cartbounty_pro_change_phone_validation' );

Abandoned cart product prices without taxes

Please use this snippet, if you would like to display abandoned cart product prices without taxes.

add_filter( 'cartbounty_pro_include_tax', '__return_false' );

Adjust Google reCAPTCHA sensitivity

In the example below we have raised the sensitivity from the default 0.2 to 0.3 – now only visitors that will receive a score of 0.3 or higher will be saved in the abandoned cart table.

function cartbounty_pro_change_score( $score ) {
	return 0.3;
}
add_filter( 'cartbounty_pro_recaptcha_minimum_allowed_score', 'cartbounty_pro_change_score' );

Customize price format

CartBounty displays prices according to WooCommerce currency settings. If you would like to override this – use the below example of how to format the price with currency positioned on the right with a space between the price, e.g. 28 $.

function cartbounty_pro_change_price_format(){
	//Currency to the left - %1$s%2$s
	//Currency to the right - %2$s%1$s
	//Currency to the left with space - %1$s %2$s
	//Currency to the right with space - %2$s %1$s
	return '%2$s %1$s';
}
add_filter( 'cartbounty_pro_price_format', 'cartbounty_pro_change_price_format' );

Display currency code instead of symbol

Please use the example below if you would like to output currency code like USD or EUR instead of $ or € symbol in the abandoned cart table and WordPress recovery emails.

function cartbounty_pro_enable_currency_code(){
	return true;
}
add_filter( 'cartbounty_pro_display_currency_code', 'cartbounty_pro_enable_currency_code' );

Change coupon expiration date format

By default coupon expiration date is formatted and displayed as 2021-08-21 (year-month-date), but it is possible to easily change the formatting via a filter.

/**
 * Other alternative examples if we assume the expiration date is set to August 21st, 2021
 * 'Y-m-d'		2021-08-21 (Default)
 * 'Y-d-m'		2021-21-08
 * 'd.m.Y'		21.08.2021
 * 'F dS, Y'	        August 21st, 2021
 * 'M d, Y'		Aug 21, 2021
 */
function cartbounty_change_coupon_expiry_date_format(){ 
	return 'Y-d-m';
}
add_filter( 'cartbounty_pro_coupon_expiry_date_format', 'cartbounty_change_coupon_expiry_date_format' );

Add additional status to unfinished orders list

Please use this snippet if you would like to add additional status to unfinished orders list using a filter instead of CartBounty settings.

function cartbounty_update_unfinished_order_statuses( $statuses ){
    $statuses[] = 'cancelled';
    return $statuses;
}
add_filter( 'cartbounty_pro_unfinished_order_statuses', 'cartbounty_update_unfinished_order_statuses' );

Change landing page

Checkout page is the default page customer is taken to after restoring cart from abandoned cart recovery email or text message. Use the following snippet to change this to WooCommerce cart page or a custom link.

function cartbounty_landing_url(){ 
    return 'cart'; // Available options: checkout (default), cart, custom link starting with https://
}
add_filter( 'cartbounty_pro_landing_url', 'cartbounty_landing_url' );

Add UTM tracking tags to abandoned cart recovery URL

CartBounty to add UTM tracking tags to links which are sent to customers in abandoned cart reminders. Once the link is clicked and customer has arrived at your store, these tags can be picked up by your tracking mechanism to have a better understanding of how well your campaigns are doing.

Please use this as an example that shows how to add 3 custom tags (utm_campaign, utm_medium and utm_source) with appropriate values to CartBounty abandoned cart reminder URL.

function cartbounty_pro_add_cart_url_utm_tracking(){
    return 'utm_campaign=recovery&utm_medium=social&utm_source=instagram';
}
add_filter( 'cartbounty_pro_cart_url_utm_tracking', 'cartbounty_pro_add_cart_url_utm_tracking' );

Stop automatic coupon application

Do not auto apply coupon code to the shopping cart once customer returns from recovery message (email or SMS).

add_filter( 'cartbounty_pro_coupon_auto_apply', '__return_false' );

Set custom preferred countries used by easy international phone input

CartBounty uses default WooCommerce base country as default country for validating phone numbers without area code as well as to display initial area code if Easy international input enabled. If you would like to keep your default store base country but would like to have a different country used by CartBounty, please use this example.

add_filter( 'cartbounty_pro_default_country', 'cartbounty_pro_change_default_country' );
function cartbounty_pro_change_default_country(){
    return 'US';
}

Set custom preferred countries used by easy international phone input

When easy international phone input is enabled, customers can select their area code from a drop-down list. To improve user experience, it is possible to edit which countries appear first in the list using the following example which moves United States, Canada and United Kingdom to the top of the list.

add_filter( 'cartbounty_pro_international_phone_preferred_countries', 'cartbounty_pro_add_phone_input_preferred_countries' );
function cartbounty_pro_add_phone_input_preferred_countries(){
    return array( 'US', 'CA', 'GB' );
}

Output full address in the location column

CartBounty does not output full customer address in the abandoned cart list. However, if it is necessary to display full customer address, it is possible to do using a filter.

add_filter( 'cartbounty_pro_display_full_address', '__return_true' );

Save custom product field plugin data

There are various WooCommerce plugins that allow adding extra product options and collect additional details from customers when adding a product to shopping cart (e.g., customer notes, dates, engrave texts etc.). CartBounty can save and restore custom product data from these plugins:

However, it is possible to add support for other custom product addon plugins using a filter and passing an additional array element into existing array.

function cartbounty_pro_edit_custom_product_fields( $fields ){
    $fields[] = 'your_custom_field_label';
    return $fields;
}
add_filter( 'cartbounty_pro_custom_product_fields', 'cartbounty_pro_edit_custom_product_fields' );

Limit exported abandoned cart table columns

CartBounty allows to export abandoned cart data. By default, all abandoned cart table columns are exported however it is possible to use a filter to specify exported columns. Here is an example how to include only Abandoned cart ID, customer email, name, and surname.

function cartbounty_pro_update_export_columns( $columns ){
    $columns = 'id, email, name, surname';
    return $columns;
}
add_filter( 'cartbounty_pro_export_columns', 'cartbounty_pro_update_export_columns' );

Please note that it is required to include id, email, and session_id fields to see abandoned cart recovery link column added to exported data.

Exclude specific countries from abandoned cart recovery

It is possible to exclude specified countries from receiving abandoned cart reminders. Please use this example to achieve it. Note that this is a global filter will also affect which abandoned carts will be synced to external services like ActiveCampaign, MailChimp etc.

function cartbounty_pro_set_excluded_countries( $countries ){
    $countries[] = 'LV'; //Replace this with country code that needs to be excluded
    $countries[] = 'US'; //Remove this line or add multiple ones to exclude multiple countries from receiving abandoned cart messages
    return $countries;
}
add_filter( 'cartbounty_pro_excluded_countries', 'cartbounty_pro_set_excluded_countries' );

Exclude customers using specific languages from abandoned cart recovery

Use this example to exclude customers using specific languages from receiving abandonment reminders.

function cartbounty_pro_set_excluded_languages( $languages ){
    $languages[] = 'en_US'; //Adding WordPress language locale code to exclusions
    $languages[] = 'lv_LV'; //Adding WordPress language locale code to exclusions
    return $languages;
}
add_filter( 'cartbounty_pro_excluded_languages', 'cartbounty_pro_set_excluded_languages' );

Exclude shopping carts from recovery that do not exceed minimum cart total

There is an option to exclude customers with specific cart total value from receiving reminders. Please use the example below to set minimum cart total value. If the cart total value is below the minimum set value, customer will not receive a reminder.

function cartbounty_pro_set_minimum_cart_total( $value ){
    $value = 50;
    return $value;
}
add_filter( 'cartbounty_pro_minimum_cart_total', 'cartbounty_pro_set_minimum_cart_total' );

3. WordPress recovery email hooks

WordPress recovery offers different email templates and each of them can be used in its own automation step. Actions and filters therefore make use of two variables – template_name which defines the template used (available strings are “light”, “rows” and “columns”) and step_number which defines the automation step (available numbers are “1”, “2” and “3”).

Actions:

  1. cartbounty_pro_automation_{template_name}_before_title_{step_number}
  2. cartbounty_pro_automation_{template_name}_after_title_{step_number}
  3. cartbounty_pro_automation_{template_name}_after_intro_{step_number}
  4. cartbounty_pro_automation_{template_name}_after_button_{step_number}
  5. cartbounty_pro_automation_{template_name}_footer_start_{step_number}
  6. cartbounty_pro_automation_{template_name}_footer_end_{step_number}

Filters:

  1. cartbounty_pro_automation_{template_name}_title_html_{step_number}
  2. cartbounty_pro_automation_{template_name}_intro_html_{step_number}
  3. cartbounty_pro_automation_{template_name}_button_html_{step_number}
  4. cartbounty_pro_automation_copyright
  5. cartbounty_pro_automation_footer_address_1
  6. cartbounty_pro_automation_footer_address_2
  7. cartbounty_pro_automation_unsubscribe_html
  8. cartbounty_pro_automation_max_products
  9. cartbounty_pro_wordpress_recovery_args
  10. cartbounty_pro_wordpress_recovery_email_bcc
Action and filter scheme of WordPress recovery email
Action and filter scheme of WordPress recovery email

Include additional content before the main title

Example how to add additional content right before the main title inside the “Light” template if it is used in the 1st WordPress recovery reminder email step.

function cartbounty_pro_add_light_title_on_step_one(){
	esc_html_e( 'Additional content before main title', 'woo-save-abandoned-carts' );
}
add_action( 'cartbounty_pro_automation_light_before_title_1', 'cartbounty_pro_add_light_title_on_step_one' );

Edit main title

How to use a filter to alter the main title of the “With cart contents” template if it is used in the 2nd automation step.

function cartbounty_pro_alter_rows_title_on_step_two( $title ){
	return '<h1 style="font-size: 60px; padding-bottom: 30px;">'. __('My new title', 'woo-save-abandoned-carts') .'</h1>';
}
add_filter( 'cartbounty_pro_automation_rows_title_html_2', 'cartbounty_pro_alter_rows_title_on_step_two' );

Change “Complete checkout” button name

How to replace existing button name from “Complete checkout” to “Return to cart” inside the “With cart contents” template if it is used in the 2nd automation step.

function cartbounty_pro_alter_rows_button_on_step_two( $button ){
    return str_replace( 'Complete checkout', __('Return to cart', 'woo-save-abandoned-carts') , $button);
}
add_filter( 'cartbounty_pro_automation_rows_button_html_2', 'cartbounty_pro_alter_rows_button_on_step_two' );

How to change the default footer address. By default, it is taken from WooCommerce store address you have entered, but you can change it using a filter.

function cartbounty_pro_alter_footer_address_1( $address ){
    esc_html_e('First address line...', 'woo-save-abandoned-carts');
}
add_filter( 'cartbounty_pro_automation_footer_address_1', 'cartbounty_pro_alter_footer_address_1' );

function cartbounty_pro_alter_footer_address_2( $address ){
    esc_html_e('Second address line...', 'woo-save-abandoned-carts');
}
add_filter( 'cartbounty_pro_automation_footer_address_2', 'cartbounty_pro_alter_footer_address_2' );

Change the maximum number of products

How to change the maximum number of products that are presented in the reminder email to 9 products.

function cartbounty_pro_alter_max_products(){
    return 9;
}
add_filter( 'cartbounty_pro_automation_max_products', 'cartbounty_pro_alter_max_products' );

Add Bcc email address to WordPress Recovery emails

If you add an email address to the Bcc field it means that a copy of the abandoned cart reminder email that will be sent to customer will also be sent to address inside Bcc field, however the customer receiving this reminder email will not be able to see the address in the Bcc field.

Here is an example how to add two Bcc emails to WordPress Recovery reminder emails.

function cartbounty_pro_add_wordpress_recovery_email_bcc(){
    $emails = "first@email.com, second@email.com";
    return $emails;
}
add_filter( 'cartbounty_pro_wordpress_recovery_email_bcc', 'cartbounty_pro_add_wordpress_recovery_email_bcc' );

4. BulkGate recovery hooks

Filters:

  1. cartbounty_pro_bulkgate_unicode

Force disable Unicode characters

When sending BulkGate text messages (SMS), CartBounty will automatically check weather reminder message contain Unicode characters or not and will instruct BulkGate enable or disable Unicode sending mode. To disable this behavior and force all messages to be sent as non-Unicode messages, please use this snippet.

add_filter( 'cartbounty_pro_bulkgate_unicode', '__return_false' );

5. Admin notification email hooks

Admin notification email template includes various actions and filters that allow to customize how the information about a newly abandoned or recovered cart is presented to the store administrator or manager.

Actions:

  1. cartbounty_pro_admin_email_before_title
  2. cartbounty_pro_admin_email_after_title
  3. cartbounty_pro_admin_email_after_intro
  4. cartbounty_pro_admin_email_after_button
  5. cartbounty_pro_admin_email_footer_end

Filters:

  1. cartbounty_pro_admin_email_title_html
  2. cartbounty_pro_admin_email_intro_html
  3. cartbounty_pro_admin_email_button_html
  4. cartbounty_pro_admin_notification_args
  5. cartbounty_pro_admin_notification_cc
  6. cartbounty_pro_admin_notification_bcc
  7. cartbounty_pro_admin_anonymize_notification_email
  8. cartbounty_pro_admin_anonymize_notification_phone

Add Bcc email address to admin notification emails

Here is an example how to add Bcc email to CartBounty admin notification emails. Similar code can be used to add Cc field. When entering multiple email addresses, they must be separated by a comma.

function cartbounty_pro_add_admin_notification_bcc(){
    $email = "email@email.com";
    return $email;
}
add_filter( 'cartbounty_pro_admin_notification_bcc', 'cartbounty_pro_add_admin_notification_bcc' );

Display customer email and phone inside admin notifications

When a new recoverable abandoned cart is saved or recovered, CartBounty sends out an email to the store administrator that contains user’s email, phone and cart value. Email and phone is obfuscated for the sake of personal data protection as it is not advisable to store personal data in more than one location. Since this data is available in the abandoned cart list – CartBounty is not creating another copy inside email, but rather shows a preview of this personal data.

However if you would still like to see full email and phone inside the notification email, please add this to your functions.php file.

add_filter( 'cartbounty_pro_admin_anonymize_notification_email', '__return_false' );
add_filter( 'cartbounty_pro_admin_anonymize_notification_phone', '__return_false' );

6. Exit Intent hooks

Our Exit Intent template contains different actions and filters that allow you to add new, edit, replace and remove existing content including the main image inside the popup.

Actions:

  1. cartbounty_pro_exit_intent_start
  2. cartbounty_pro_exit_intent_after_title
  3. cartbounty_pro_exit_intent_before_form_fields
  4. cartbounty_pro_exit_intent_end

Filters:

  1. cartbounty_pro_exit_intent_close_html
  2. cartbounty_pro_exit_intent_image_html
  3. cartbounty_pro_exit_intent_title_html
  4. cartbounty_pro_exit_intent_description_html
  5. cartbounty_pro_exit_intent_field_html
  6. cartbounty_pro_exit_intent_button_html
  7. cartbounty_pro_exit_intent_reset_hours
  8. cartbounty_pro_exit_intent_args
Action and filter scheme of Exit Intent popup

Change the main title

If you are looking to change the default title of Exit Intent popup, you can use cartbounty_pro_exit_intent_title_html filter and this snippet below.

function modify_title( $html ) {
	$custom_title = 'Your text here...';
	return preg_replace('#(<h2[^>]*>).*?(</h2>)#', "$1 $custom_title $2", $html);
}
add_filter( 'cartbounty_pro_exit_intent_title_html', 'modify_title' );

Edit description

If you are looking to change the default description of Exit Intent popup, you can use cartbounty_pro_exit_intent_description_html filter and this snippet below.

function modify_description( $html ){
	$custom_description = 'New description here...';
	return preg_replace('#(<p[^>]*>).*?(</p>)#', "$1 $custom_description $2", $html);
}
add_filter( 'cartbounty_pro_exit_intent_description_html', 'modify_description' );

Add a subtitle

Here is an example how to add an additional subtitle after the main title using cartbounty_pro_exit_intent_after_title action hook.

function add_extra_html_after_title() {
	echo "<p>Additional subtitle here...</p>";
}
add_action('cartbounty_pro_exit_intent_after_title', 'add_extra_html_after_title' );

Replace the image

Example how to use cartbounty_pro_exit_intent_image_html filter to replace the default image using a function.

function modify_image( $html ){
	return '<img src="http://www.link-to-your-custom-image-here..."/>';
}
add_filter( 'cartbounty_pro_exit_intent_image_html', 'modify_image' );

7. Early capture hooks

Early capture template contains different actions and filters that allow you to add new, edit, replace and remove existing content.

Actions:

  1. cartbounty_pro_early_capture_after_title
  2. cartbounty_pro_early_capture_before_form_fields

Filters:

  1. cartbounty_pro_early_capture_label_html
  2. cartbounty_pro_early_capture_close_html
  3. cartbounty_pro_early_capture_field_html
  4. cartbounty_pro_early_capture_button_html
  5. cartbounty_pro_early_capture_reset_hours
  6. cartbounty_pro_early_capture_args

Edit appearance time interval

How to change the default time interval of how often the “Add to cart” popup request is presented from 60 to 30 minutes.

function custom_early_capture_appearance_interval( $hours ){
	return 0.5;
}
add_filter( 'cartbounty_pro_early_capture_reset_hours', 'custom_early_capture_appearance_interval' );

8. Tab notification hooks

Tab notification provides a couple of filters for additional customization which is outside the scope of what is already available under Tab notification settings.

Filters:

  1. cartbounty_pro_tab_notification_interval
  2. cartbounty_pro_tab_notification_favicon
  3. cartbounty_pro_tab_notification_favicon_relationship

Customize Tab title and Favicon speed

CartBounty Tab notification allows to choose from a list of various Intervals when Tab title and Favicon should switch. However, it is possible to use a filter to set a custom time Interval. Here is an example how to set dynamic Tab notification interval to 7 seconds.

function cartbounty_pro_change_tab_notification_interval( $interval ){
    $interval = 7000; //Value in milliseconds
    return $interval;
}

add_filter( 'cartbounty_pro_tab_notification_interval', 'cartbounty_pro_change_tab_notification_interval' );

Set a custom Favicon image URL

It is very easy to add a custom Favicon icon via CartBounty Tab notification settings. But there is a filter that allows to set a custom image URL. An example you can use to load Favicon image from an external URL.

function cartbounty_pro_change_tab_notification_favicon_url( $url ){
    $url = 'https://www.apple.com/favicon.ico';
    return $url;
}

add_filter( 'cartbounty_pro_tab_notification_favicon', 'cartbounty_pro_change_tab_notification_favicon_url' );

Customize Favicon link tag relationship

Tab notification allows to use Favicon as means of attracting customer attention and returning them to your store. In most cases Favicon is defined using <link rel="icon"> tag and CartBounty is relying on “rel” attribute. By default, CartBounty is looking for the attribute to be set to “icon” or “shortcut icon”. But in case you have different relationship, you can use a custom filter and add this attribute to the list. Here is an example where we add “favicon” attribute to the default list of attributes.

function cartbounty_pro_change_tab_notification_favicon_relationship( $relationship ){
    $relationship = 'icon, shortcut icon, favicon';
    return $relationship;
}

add_filter( 'cartbounty_pro_tab_notification_favicon_relationship', 'cartbounty_pro_change_tab_notification_favicon_relationship' );

9. Privacy and GDPR data export hooks

These hooks are intended to help with abandoned cart personal data anonymization and the default WordPress GDPR data export tool.

Filters:

  1. cartbounty_pro_anonymization_interval
  2. cartbounty_pro_export_abandoned_cart_fields
  3. cartbounty_pro_export_abandoned_cart_field
  4. cartbounty_pro_export_abandoned_cart

What’s next

You might also be interested in these topics:

Last updated 2 weeks ago

Support

Need premium support for CartBounty Pro?

Please use the button below, reply to your purchase receipt or contact us with e-mail including your license key. This will guarantee a faster response time.

Get Premium support
CartBounty

You were not leaving your cart just like that, right?

Enter your details below to save your shopping cart for later. And, who knows, maybe we will even send you a sweet discount code :)