WooCommerce Hooks Reference
Developer documentation for customizing BuddyX Pro’s WooCommerce integration.
Filter Hooks
buddyxoffcanvasfilterbutton_output
Customize the off-canvas filter button HTML output.
add_filter( 'buddyx_off_canvas_filter_button_output', 'my_custom_filter_button' );
function my_custom_filter_button( $output ) {
return '';
}
Parameters:
$output(string) – Default button HTML
Return: String – Modified button HTML
woocommerceaddtocartfragments
BuddyX Pro uses this WooCommerce filter to update cart elements via AJAX.
add_filter( 'woocommerce_add_to_cart_fragments', 'my_custom_fragments' );
function my_custom_fragments( $fragments ) {
// Add custom fragment
$fragments['.my-custom-cart-element'] = '' .
WC()->cart->get_cart_contents_count() . ' items';
return $fragments;
}
Theme-registered fragments:
.menu-icons-wrapper .cart a– Header cart icon with count.buddyx-mini-cart– Mini cart contents.buddyx-cart-count– Cart item count.buddyx-cart-contents– Cart summary text
woocommercesaleflash
Customize the sale badge output when percentage display is enabled.
add_filter( 'woocommerce_sale_flash', 'my_sale_badge', 10, 3 );
function my_sale_badge( $badge, $post, $product ) {
// Custom sale badge with different styling
return 'SALE!';
}
Note: Theme only modifies this when buddyxwoosalebadgecontent is set to ‘percent’.
post_class
BuddyX Pro adds WooCommerce-specific classes to products.
add_filter( 'post_class', 'my_product_classes', 50, 3 );
function my_product_classes( $classes, $class, $post_id ) {
if ( ! function_exists( 'wc_get_product' ) ) {
return $classes;
}
$product = wc_get_product( $post_id );
if ( ! $product ) {
return $classes;
}
// Add custom class for products on sale
if ( $product->is_on_sale() ) {
$classes[] = 'my-custom-sale-class';
}
return $classes;
}
Theme-added classes:
square-sale– When sale badge style is squarecircle-sale– When sale badge style is circleleft-position– When sale badge position is left
loopshopper_page
Control products displayed per page.
add_filter( 'loop_shop_per_page', 'my_products_per_page', 30 );
function my_products_per_page( $count ) {
// Show 24 products per page
return 24;
}
Note: Theme sets this based on buddyxwooproductperpage customizer setting.
Action Hooks
woocommercebeforeshop_loop
BuddyX Pro adds the filter button here (priority 10).
// Add custom element before shop loop
add_action( 'woocommerce_before_shop_loop', 'my_shop_intro', 5 );
function my_shop_intro() {
if ( is_shop() ) {
echo 'Welcome to our shop!';
}
}
woocommerceaftercart_form
Cross-sell products are moved here from their default location.
// Add custom content after cart
add_action( 'woocommerce_after_cart_form', 'my_cart_message', 5 );
function my_cart_message() {
echo '';
}
wp_footer
Theme adds quantity button scripts here.
// Add custom WooCommerce scripts
add_action( 'wp_footer', 'my_woo_scripts', 20 );
function my_woo_scripts() {
if ( ! is_woocommerce() && ! is_cart() ) {
return;
}
?>
Theme Functions
buddyxrendercart_icon()
Renders the shopping cart icon with item count.
// Use in custom template
if ( function_exists( 'buddyx_render_cart_icon' ) ) {
buddyx_render_cart_icon();
}
Output:
buddyxcartwidget_side()
Outputs the mini cart sidebar widget.
// Use in custom template
if ( function_exists( 'buddyx_cart_widget_side' ) ) {
buddyx_cart_widget_side();
}
buddyxfilterswidget_side()
Outputs the off-canvas filter sidebar.
// Use in custom template
if ( function_exists( 'buddyx_filters_widget_side' ) ) {
buddyx_filters_widget_side();
}
buddyxiswoo_shop()
Check if current page is the WooCommerce shop page.
if ( buddyx_is_woo_shop() ) {
// We're on the shop page
}
Returns: Boolean
buddyxiswoo_tax()
Check if current page is a WooCommerce taxonomy archive.
if ( buddyx_is_woo_tax() ) {
// We're on a product category/tag page
}
Returns: Boolean
Customizer Settings
Getting Customizer Values
// Sale badge style
$sale_style = get_theme_mod( 'buddyx_woo_sale_badge_style', 'default' );
// Sale badge position
$sale_position = get_theme_mod( 'buddyx_woo_sale_badge_position', 'right' );
// Sale badge content type
$sale_content = get_theme_mod( 'buddyx_woo_sale_badge_content', 'text' );
// Product style
$product_style = get_theme_mod( 'woocommerce_product_style', 'default' );
// Show sorting dropdown
$show_sort = get_theme_mod( 'buddyx_woo_shop_sort', true );
// Show result count
$show_count = get_theme_mod( 'buddyx_woo_shop_result_count', true );
// Products per page
$per_page = get_theme_mod( 'buddyx_woo_product_per_page', 16 );
// Off canvas filter enabled
$filter_enabled = get_theme_mod( 'buddyx_woo_off_canvas_filter', false );
// Filter button text
$filter_text = get_theme_mod( 'buddyx_woo_off_canvas_filter_text', 'Filter' );
Removing Theme Modifications
Restore WooCommerce Breadcrumbs
add_action( 'init', function() {
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
}, 15 );
Restore Default Sidebar
add_action( 'init', function() {
add_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
}, 15 );
Restore Cross-Sells Location
add_action( 'init', function() {
remove_action( 'woocommerce_after_cart_form', 'woocommerce_cross_sell_display', 10 );
add_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
}, 15 );
Restore Default Sort/Count
add_action( 'init', function() {
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
}, 15 );
CSS Classes
Sale Badge Classes
| Class | Applied When |
|---|---|
.onsale | Default WooCommerce sale badge |
.square-sale | Sale badge style is “Square” |
.circle-sale | Sale badge style is “Circle” |
.left-position | Sale badge position is “Left” |
Cart Classes
| Class | Element |
|---|---|
.cart-widget-opener | Cart icon container |
.buddyx-cart-widget-side | Mini cart sidebar |
.buddyx-mini-cart | Mini cart contents |
.buddyx-cart-count | Cart count badge |
.buddyx-cart-contents | Cart summary |
Filter Classes
| Class | Element |
|---|---|
.buddyx-woo-canvas-filter | Filter button |
.buddyx-filter-widget-side | Filter sidebar |
.woo-off-canvas-sidebar | Filter sidebar content |
Shop Classes
| Class | Applied When |
|---|---|
.infinite-loader-active | Infinite Loader plugin is active |
JavaScript Events
Mini Cart Open/Close
jQuery(document).ready(function($) {
// Cart widget opened
$(document).on('click', '.cart-widget-opener', function(e) {
console.log('Mini cart opened');
});
// Cart widget closed
$(document).on('click', '.widget-close', function(e) {
console.log('Mini cart closed');
});
});
Quantity Button Events
jQuery(document).ready(function($) {
// Quantity changed via +/- buttons
$(document.body).on('click', '.plus, .minus', function() {
console.log('Quantity changed');
});
});
Related Documentation
- README – Technical overview
- Customer Guide – Setup instructions
- Developer Hooks – All theme hooks
