WooCommerce Hooks Reference

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 square
  • circle-sale – When sale badge style is circle
  • left-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 '
Free shipping on orders over $50!
'; }

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

ClassApplied When
.onsaleDefault WooCommerce sale badge
.square-saleSale badge style is “Square”
.circle-saleSale badge style is “Circle”
.left-positionSale badge position is “Left”

Cart Classes

ClassElement
.cart-widget-openerCart icon container
.buddyx-cart-widget-sideMini cart sidebar
.buddyx-mini-cartMini cart contents
.buddyx-cart-countCart count badge
.buddyx-cart-contentsCart summary

Filter Classes

ClassElement
.buddyx-woo-canvas-filterFilter button
.buddyx-filter-widget-sideFilter sidebar
.woo-off-canvas-sidebarFilter sidebar content

Shop Classes

ClassApplied When
.infinite-loader-activeInfinite 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

Last updated: January 31, 2026