Skip to main content

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​

ArgumentTypeDescription
$attributesArrayHolds the HTML attributes
$typeStringButton 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​

ArgumentTypeDescription
$classesArrayHolds the HTML classes
$typeStringButton 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 );