1. WooCommerce Bulk Variations
  2. Developer Documentation

Actions and Filters

There are a number of filters provided in WooCommerce Bulk Variations which allow you to customize the behavior of the plugin.

Please note that this article is aimed at developers. If you don't know how to use this code then you should ask your developer.

We've partnered with Codeable to provide our customers with expert help if required.

Filters

Language filters

There are various filters provided for manipulating text strings and messages used in the plugin. Please refer to this article for filters to override the text strings.

wc_bulk_variations_get_table_output

Filter the output of all Bulk Variations tables on the site. $table may be an Object (default), HTML string, Array object, or a JSON string, which is specified by the $return_type parameter using the string 'object', 'html', 'array', or 'json'.

add_filter( 'wc_bulk_variations_get_table_output', function( $table, $return_type ) {
    // do something with $table
    return $table; 
} );

wc_bulk_variations_product_output

Filter the output of the Bulk Variations table html displayed within product templates.

add_filter( 'wc_bulk_variations_product_output', function( $html ) { 
    return '<div class="my-table-wrapper">' . $html . '</div>'; 
} );

wc_bulk_variations_shortcode_output

Filter the output of the Bulk Variations table html displayed by a shortcode.

add_filter( 'wc_bulk_variations_shortcode_output', function( $html ) { 
    return '<div class="my-shortcode-wrapper">' . $html . '</div>'; 
} );

wc_bulk_variations_table_row_attributes

Filter the attributes attached to each row of the Bulk Variations table. Provides the id and class attributes by default. Expects an array to be returned.

add_filter( 'wc_bulk_variations_table_row_attributes', function( $attributes ) { 
    $attributes['class'] .= ' custom-table-row-class';
    return $attributes; 
} );

woocommerce_add_to_cart_validation

Filter the validation of a product being added to the cart, filter provides the product ID ($product_id), quantity ($qty), product variation ID ($variation_id), and a collection of all variations available ($all_variations).

add_filter( 'woocommerce_add_to_cart_validation', function( $valid, $product_id, $qty, $variation_id, $all_variations ) { 
    // change $valid to the boolean `false` to show an error when the user adds this product to their cart
    return $valid; 
}, 10, 5 );

woocommerce_default_quantity_value

Filter the default quantity of each bulk variation input, filter provides the WC_Product_Variation ($product_variation) object. This filter will only be applied if the WooCommerce Default Quantity plugin is installed.

add_filter( 'woocommerce_default_quantity_value', function( $value, $product_variation ) { 
    return 1; 
}, 10, 2 );

wc_bulk_variations_table_cell_output

Filter the output of each individual <td> cell in the Bulk Variations table. Provides the WC_Product_Variation ($product_variation) object.

add_filter( 'wc_bulk_variations_table_cell_output', function( $html, $product_variation ) { 
    return '<span class="wbv-table-cell-wrapper">' . $html . '</span>'; 
}, 10, 2 );

wc_bulk_variations_stock_message

Filter the output of the 'Out of Stock' message displayed underneath the quantity input. Provides the WC_Product_Variation ($product_variation) object.

add_filter( 'wc_bulk_variations_stock_message', function( $message, $product_variation ) { 
    return 'Unavailable'; 
}, 10, 2 );

wc_bulk_variations_single_variation_header

Filter the string used as the header of the main column on single-attribute grids (in both horizontal and vertical orientations).

add_filter( 'wc_bulk_variations_single_variation_header', function( $header ) { 
    return 'Quantity'; 
} );

Actions

wc_bulk_variations_table_load_scripts

Fired after WooCommerce Bulk Variations scripts and stylesheets have been enqueued, from within the wp_enqueue_scripts action.

wc_bulk_variations_table_before_get_data

Fired before the data within a WooCommerce Bulk Variations table is generated. Provides WC_Bulk_Variations_Table object.

wc_bulk_variations_table_after_get_data

Fired after the data within a WooCommerce Bulk Variations table is generated. Provides WC_Bulk_Variations_Table object.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.