PHP Filters
A breakdown of all the PHP Filters in CartPops.
note
Please keep in mind that the CartPops API is subject to change. Before updating, please check the changelog to learn what has changed and whether you can safely upgrade.
cartpops_checkout_button_urlβ
This filter allows you to change the checkout URL.
π Exampleβ
/**
* Change the checkout button URL.
*
* @param string $url The checkout URL. Default is wc_get_checkout_url().
*/
function my_prefix_cartpops_checkout_url( $url ) {
$url = esc_url( get_permalink( get_page_by_title( 'Some page' ) ) );
return $url;
}
add_filter( 'cartpops_checkout_button_url', 'my_prefix_cartpops_checkout_url', 10, 1 );
cartpops_empty_cart_button_urlβ
This filter allows you to change the button URL when there are no items in the cart.
π Exampleβ
/**
* Change the empty cart button URL.
*
* @param string $url The empty button URL. Default is get_permalink( wc_get_page_id( 'shop' ) ).
*/
function my_prefix_cartpops_empty_cart_url( $url ) {
$url = esc_url( get_permalink( get_page_by_title( 'Some page' ) ) );
return $url;
}
add_filter( 'cartpops_empty_cart_button_url', 'my_prefix_cartpops_empty_cart_url', 10, 1 );
cartpops_drawer_classesβ
Filter the classes added to the Drawer.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_drawer( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_classes', 'my_prefix_classes_drawer', 10, 1 );
cartpops_drawer_empty_cart_classesβ
Filter the classes added to the Drawer when the cart is empty.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_empty_drawer( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_empty_cart_classes', 'my_prefix_classes_empty_drawer', 10, 1 );
cartpops_alt_trigger_classesβ
Filter the classes added to any trigger other than the Drawer.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_alt_trigger( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_alt_trigger_classes', 'my_prefix_classes_alt_trigger', 10, 1 );
cartpops_floating_cart_launcher_classesβ
Filter the classes added to the Floating Cart Launcher.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_cart_launcher( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_floating_cart_launcher_classes', 'my_prefix_classes_cart_launcher', 10, 1 );
cartpops_drawer_header_classesβ
Filter the classes added to the Drawer header.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_drawer_header( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_header_classes', 'my_prefix_classes_drawer_header', 10, 1 );
cartpops_drawer_shipping_meter_classesβ
Filter the classes added to the Free Shipping Meter in the Drawer.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_drawer_shipping_meter( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_shipping_meter_classes', 'my_prefix_classes_drawer_shipping_meter', 10, 1 );
cartpops_drawer_cart_item_classesβ
Filter the classes added to a single cart item.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_single_cart_item( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_cart_item_classes', 'my_prefix_classes_single_cart_item', 10, 1 );
cartpops_drawer_coupon_form_classesβ
Filter the classes added to the Coupon form in the Drawer.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_drawer_coupon_form( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_coupon_form_classes', 'my_prefix_classes_drawer_coupon_form', 10, 1 );
cartpops_drawer_recommendations_classesβ
Filter the classes added to the Drawer recommendations.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_drawer_recommendations( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_recommendations_classes', 'my_prefix_classes_drawer_recommendations', 10, 1 );
cartpops_drawer_cart_totals_classesβ
Filter the classes added to the Drawer totals.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_drawer_totals( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_drawer_cart_totals_classes', 'my_prefix_classes_drawer_totals', 10, 1 );
cartpops_single_line_item_classesβ
Filter the classes added to a single line item.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_alt_trigger( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_alt_trigger_classes', 'my_prefix_classes_alt_trigger', 10, 1 );
cartpops_single_line_item_classesβ
Filter the classes added to a single line item.
π Exampleβ
/**
* Filter the subtotal HTML
*
* @param string $html String containing HTML.
*/
function my_prefix_html_subtotal( $html ) {
// do something with $html
return $html;
}
add_filter( 'cartpops_cart_totals_subtotal_html', 'my_prefix_html_subtotal', 10, 1 );
cartpops_cart_totals_subtotal_total_htmlβ
Filter the subtotal HTML.
π Exampleβ
/**
* Filter the subtotal HTML
*
* @param string $html String containing HTML.
*/
function my_prefix_html_subtotal( $html ) {
// do something with $html
return $html;
}
add_filter( 'cartpops_cart_totals_subtotal_html', 'my_prefix_html_subtotal', 10, 1 );
cartpops_cart_totals_order_total_htmlβ
Filter the order total HTML.
π Exampleβ
/**
* Filter the order total HTML
*
* @param string $html String containing HTML.
*/
function cartpops_cart_totals_vat_total_html( $html ) {
// do something with $html
return $html;
}
add_filter( 'cartpops_cart_totals_order_total_html', 'my_prefix_html_order_total', 10, 1 );
cartpops_cart_totals_vat_total_htmlβ
Filter the vat total HTML.
π Exampleβ
/**
* Filter the VAT total HTML.
*
* @param string $html String containing HTML.
*/
function my_prefix_html_subtotal( $html ) {
// do something with $html
return $html;
}
add_filter( 'cartpops_cart_totals_vat_total_html', 'my_prefix_html_subtotal', 10, 1 );
cartpops_cart_totals_discount_total_htmlβ
Filter the discount total HTML.
π Exampleβ
/**
* Filter the discount total HTML.
*
* @param string $html String containing HTML.
*/
function my_prefix_html_discount_total( $html ) {
// do something with $html
return $html;
}
add_filter( 'cartpops_cart_totals_discount_total_html', 'my_prefix_html_discount_total', 10, 1 );
cartpops_secondary_btn_attributesβ
Filter the secondary button attributes.
π Argumentsβ
| Argument | Type | Description |
|---|---|---|
| $attributes | Array | Holds the HTML attributes |
| $type | String | Button type |
π Exampleβ
/**
* Add or filter the secondary button attributes.
*
* @param array $attributes Array of HTML atrributes.
* @param string $type The secondary button type.
*/
function my_prefix_secondary_btn_attributes( $attributes, $type ) {
if ( 'custom_url' === $type ) {
$attributes[] = 'target="_blank"';
$attributes[] = 'rel="nofollow"';
}
return $attributes;
}
add_filter( 'cartpops_secondary_btn_attributes', 'my_prefix_secondary_btn_attributes', 10, 2 );
cartpops_secondary_btn_classesβ
Filter the secondary button classes.
π Argumentsβ
| Argument | Type | Description |
|---|---|---|
| $classes | Array | Holds the HTML classes |
| $type | String | Button type |
π Exampleβ
/**
* Add or filter the secondary button classes.
*
* @param array $classes Array of HTML classes.
* @param string $type The secondary button type.
*/
function my_prefix_secondary_btn_classes( $classes, $type ) {
if ( 'custom_url' === $type ) {
$classes[] = 'dj-khaled';
$classes[] = 'another-one';
}
return $classes;
}
add_filter( 'cartpops_secondary_btn_classes', 'my_prefix_secondary_btn_classes', 10, 2 );
cartpops_cart_launcher_classesβ
Filter the classes added to the to the Cart Launcher. Applies to all instances, including the Elementor integration.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_cart_launcher( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_cart_launcher_classes', 'my_prefix_classes_cart_launcher', 10, 1 );
cartpops_popup_recommendations_classesβ
Filter the classes added to the Popup recommendations.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_popup_recommendations( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_popup_recommendations_classes', 'my_prefix_classes_popup_recommendations', 10, 1 );
cartpops_last_cart_item_classesβ
Filter the classes for the last cart item for any trigger other than the Drawer.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_last_cart_item( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_last_cart_item_classes', 'my_prefix_classes_last_cart_item', 10, 1 );
cartpops_powered_by_classesβ
Filter the classes added to the Powered By element.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_powered_by( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_powered_by_classes', 'my_prefix_classes_powered_by', 10, 1 );
cartpops_assistant_content_classesβ
Filter the classes added to the Assistant.
π Exampleβ
/**
* Add or filter (specific) classes.
*
* @param array $classes Array of HTML class names.
*/
function my_prefix_classes_assistant( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'cartpops_assistant_content_classes', 'my_prefix_classes_assistant', 10, 1 );
cartpops_assistant_contentβ
Filter or add items to the Assistant modal.
π Exampleβ
/**
* Add or filter (specific) items in the Assistant modal.
*
* @param array $items Array of Assistant items.
*/
function my_prefix_assistant_items( $items ) {
ob_start();
?>
<h2>Hello world!</h2>
<?php
$custom_template = ob_get_clean();
$items['custom_content'] = array(
'classes' => array( 'assistant-custom-content', 'another-class' ), // CSS classes.
'title' => __( 'My title', 'cartpops' ), // Header title.
'template' => $custom_template, // HTML template
);
return $items;
}
add_filter( 'cartpops_drawer_classes', 'my_prefix_assistant_items', 10, 1 );
cartpops_notification_remove_delayβ
Change after how many milliseconds any notifications disappear. Default is 4200 (4.2 seconds).
π Exampleβ
function my_prefix_notification_delay() {
// Change time to 8 seconds.
return 8000;
}
add_filter( 'cartpops_notification_remove_delay', 'my_prefix_notification_delay', 10, 1 );
cartpops_add_to_cart_triggerβ
This filter allows you to change what add to cart trigger is being used.
π Exampleβ
/**
* Change the add to cart trigger. "none" will not open any popup.
*
* @param string $trigger Returns drawer by default. Other options are popup, bar and none. If you set the trigger to none, no popup will be triggered.
*/
function my_prefix_cartpops_add_to_cart_trigger( $trigger ) {
$trigger = 'none';
return $trigger;
}
add_filter( 'cartpops_add_to_cart_trigger', 'my_prefix_cartpops_add_to_cart_trigger', 10, 1 );
cartpops_drawer_notice_htmlβ
Alter the notification HTML or remove notifications completely.
π Example: Change the final HTML outputβ
/**
* Filter the notification HTML output.
*
* @param string $notiifcation Notification HTML partial
*/
function my_prefix_alter_notification( $notification ) {
$notification = str_replace( 'cpops-notification', 'custom-class', $notification );
return $notification;
}
add_filter( 'cartpops_drawer_notice_html', 'my_prefix_alter_notification', 10, 1 );
π Example: Remove all notificationsβ
/**
* Remove all CartPops notifications
*
* @param string $notiifcation Notification HTML partial
*/
function my_prefix_remove_all_notifications( $notification ) {
return '';
}
add_filter( 'cartpops_drawer_notice_html', 'my_prefix_remove_all_notifications', 10, 1 )
cartpops_after_cart_item_name_hook_collapsibleβ
This filter allows you to change whether the collapsible βView detailsβ below a product name shows up.
π Exampleβ
/**
* Do not show the collapsible "View deteils" below a product name
*
*/
function my_prefix_cartpops_view_details() {
return false;
}
add_filter( 'cartpops_after_cart_item_name_hook_collapsible', 'my_prefix_cartpops_view_details', 10, 1 );