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.
- Introduction to hooks
- General hooks
- WordPress recovery email hooks
- BulkGate recovery hooks
- Admin notification email hooks
- Exit Intent hooks
- Early capture hooks
- Privacy and GDPR data export hooks
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:
cartbounty_pro_from_email
cartbounty_pro_waiting_time
cartbounty_pro_phone_validation
cartbounty_pro_include_tax
cartbounty_pro_recaptcha_minimum_allowed_score
cartbounty_pro_price_format
cartbounty_pro_display_currency_code
cartbounty_pro_coupon_expiry_date_format
cartbounty_pro_unfinished_order_statuses
cartbounty_pro_landing_url
cartbounty_pro_coupon_auto_apply
cartbounty_pro_default_country
cartbounty_pro_international_phone_preferred_countries
cartbounty_pro_display_full_address
cartbounty_pro_custom_product_fields
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' );
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:
- Product Addons for Woocommerce
- Advanced Product Fields (Product Addons) for WooCommerce
- Extra Product Options (Product Addons) for WooCommerce
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' );
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:
cartbounty_pro_automation_{template_name}_before_title_{step_number}
cartbounty_pro_automation_{template_name}_after_title_{step_number}
cartbounty_pro_automation_{template_name}_after_intro_{step_number}
cartbounty_pro_automation_{template_name}_after_button_{step_number}
cartbounty_pro_automation_{template_name}_footer_start_{step_number}
cartbounty_pro_automation_{template_name}_footer_end_{step_number}
Filters:
cartbounty_pro_automation_{template_name}_title_html_{step_number}
cartbounty_pro_automation_{template_name}_intro_html_{step_number}
cartbounty_pro_automation_{template_name}_button_html_{step_number}
cartbounty_pro_automation_copyright
cartbounty_pro_automation_footer_address_1
cartbounty_pro_automation_footer_address_2
cartbounty_pro_automation_unsubscribe_html
cartbounty_pro_automation_max_products
cartbounty_pro_wordpress_recovery_args
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. BulkGate recovery hooks
Filters:
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:
cartbounty_pro_admin_email_before_title
cartbounty_pro_admin_email_after_title
cartbounty_pro_admin_email_after_intro
cartbounty_pro_admin_email_after_button
cartbounty_pro_admin_email_footer_end
Filters:
cartbounty_pro_admin_email_title_html
cartbounty_pro_admin_email_intro_html
cartbounty_pro_admin_email_button_html
cartbounty_pro_admin_notification_args
cartbounty_pro_admin_anonymize_notification_email
cartbounty_pro_admin_anonymize_notification_phone
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:
cartbounty_pro_exit_intent_start
cartbounty_pro_exit_intent_after_title
cartbounty_pro_exit_intent_before_form_fields
cartbounty_pro_exit_intent_end
Filters:
cartbounty_pro_exit_intent_close_html
cartbounty_pro_exit_intent_image_html
cartbounty_pro_exit_intent_title_html
cartbounty_pro_exit_intent_description_html
cartbounty_pro_exit_intent_field_html
cartbounty_pro_exit_intent_button_html
cartbounty_pro_exit_intent_reset_hours
cartbounty_pro_exit_intent_args
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:
cartbounty_pro_early_capture_after_title
cartbounty_pro_early_capture_before_form_fields
Filters:
cartbounty_pro_early_capture_label_html
cartbounty_pro_early_capture_close_html
cartbounty_pro_early_capture_field_html
cartbounty_pro_early_capture_button_html
cartbounty_pro_early_capture_reset_hours
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. 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:
cartbounty_pro_anonymization_interval
cartbounty_pro_export_abandoned_cart_fields
cartbounty_pro_export_abandoned_cart_field
cartbounty_pro_export_abandoned_cart
What’s next
You might also be interested in these topics:
- Personalize recovery emails using dynamic content
- How to customize CartBounty using templates
- Replace strings and translate the contents of CartBounty