1. WooCommerce Variation Prices
  2. Developer Documentation

Actions and Filters

WooCommerce Variation Prices contains a number of hooks that you can use to customize the plugin's behavior.

Please note that this code is aimed at developers and if you don't know how to use it then you should ask your developer. If you don't have one, we recommend posting a job on Codeable. We have partnered with them to provide plugin customizations for our customers.

Need professional assistance?
We've partnered with Codeable to provide our customers with expert help if required.

Filters

wc_variation_prices_is_product_affected

Filter that allows you to override whether the plugin has any effect on a given product or under specific conditions. Returns a boolean.

add_filter( 'wc_variation_prices_is_product_affected', function( $is_product_affected, $product ) {
    // do something to alter $is_product_affected;
    return $is_product_affected;
}, 10, 2 );

The following code snippet would make the plugin effective only on the Shop page.

add_filter( 'wc_variation_prices_is_product_affected', 'is_shop' );

Please consider that it is safe to use the WooCommerce conditional function is_shop as a callback function name in this case because, by the time the filter is invoked, WooCommerce Variation Prices has already verified whether WooCommerce is active or not. Thus, there is no need to check the existence of that function.

wc_variation_prices_price_range_html

Filter that allows you to override the HTML output of the plugin. This filter completely overrides the output of WooCommerce Variations Prices. Returns a string.

add_filter( 'wc_variation_prices_price_range_html', function( $html, $product ) {
    // do something to alter $html;
    return $html;
}, 10, 2 );

wc_variation_prices_price_range_classes

Filter that allows you to add your custom classes to the element enclosing the price range. Returns an array of strings.

add_filter( 'wc_variation_prices_price_range_classes', function( $classes, $product ) {
    $classes[] = 'your-custom-class';
    return $classes;
}, 10, 2 );

wc_variation_prices_list_tagname

Filter that allows you to override the tagName used to enclose the list of variations when the option "List of all variations" is selected. The default tagName is span. Returns a string.

add_filter( 'wc_variation_prices_list_tagname', function( $tagname ) {
    // do something to alter $tagname;
    return $tagname;
} );

wc_variation_prices_list_item_template

Filter that allows you to override the HTML template of the single list item, when "List of all variations" is the selected display format.  The item template must contain three placeholders that will be replaced with:

  • %1$s, the variation id
  • %2$s, the variation name
  • %3$s, the variation price.

The filter returns a string.

add_filter( 'wc_variation_prices_list_item_template', function( $html, $product ) {
    // create your HTML template and assign it to $html
    return $html;
}, 10, 2 );

wc_variation_prices_list_html

Filter that allows you to override the html markup of the list of variations. Returns a string.

add_filter( 'wc_variation_prices_list_html', function( $html, $product ) {
    // do something to alter $html;
    return $html;
}, 10, 2 );

wc_variation_prices_display_format

Filter that allows you to override the display format selected in the settings. Returns a string, that should be one of the following values: default, from, plus, upto, list or custom.

add_filter( 'wc_variation_prices_display_format', function( $format, $product ) { 
    // do something to alter $format
    return $format;
}, 10, 2 );

This filter can be used to select a format, different from the global one selected in the settings, depending on the product or other criteria.

add_filter( 'wc_variation_prices_display_format', function( $format, $product ) {

    // Select the format 'upto' for the products in the shop loop
    if ( did_action( 'woocommerce_before_shop_loop_item' ) > did_action( 'woocommerce_after_shop_loop_item' ) ) {
        $format = 'upto';
    }

    // Select the default format if the product has more than 10 variations
    // (e.g. to avoid long lists when "List of all variations"
    // is selected as a global option
    if ( count( $product->get_children() ) > 10 ) {
        $format = 'default';
    }
    return $format;
}, 10, 2 );

Related Articles

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