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_completed_order_statuses

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' );

Remove unfinished orders from abandoned cart recovery

Please use this snippet if you would like to remove from abandoned cart recovery all orders including ones that haven’t been paid for and have the status “Pending”, “Failed”, “Canceled” and “On Hold”.

function cartbounty_update_completed_order_statuses( $statuses ){
	$statuses[] = 'on-hold';
	$statuses[] = 'cancelled';
	$statuses[] = 'pending';
	$statuses[] = 'failed';
	return $statuses;
}
add_filter( 'cartbounty_pro_completed_order_statuses', 'cartbounty_update_completed_order_statuses' );

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
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' );

Edit footer address

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' );

4. 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:

6. cartbounty_pro_admin_email_title_html
7. cartbounty_pro_admin_email_intro_html
8. cartbounty_pro_admin_email_button_html

5. 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
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' );

6. 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

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' );

7. 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 7 hours 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