Start a project

Modify Variations Table DataTables Options

You can modify the settings of a variations datatable with our filter. The filter to use is “woocommerce_variations_table_datatables_options”.

In this example for the product ID 581 we disable the filtering and for product 605 we enable paging.

add_filter( 'woocommerce_variations_table_datatables_options', 'datatable_options', 10, 1 );
function datatable_options($options) {
	global $product;
	$product_id = $product->get_id();
	if($product_id == 581) {
		$options['searching'] = true;
		$options['filtering'] = false;
		$options['buttons'] = array();
	}
	if($product_id == 605) {
		$options['searching'] = true;
		$options['filtering'] = false;
		$options['paging'] = true;
		$options['ScrollCollapse'] = true;
		$options['scrollY'] = '450px';
		$options['buttons'] = array();
	}
    return $options;
}

Questions & answers (3)

  1. JukkaJuly 20, 2022

    What would be the option to disable add to cart button?

  2. DanielJuly 20, 2022

  3. JukkaJuly 20, 2022

    I was after a solution to hide price and add to cart button when product price is 0. Pasted solution below for future searches.

    /* remove add to cart and price from variation table if price is 0 */
    function modify_variations_table_data($data) {
    global $product;
    $product->get_id();
    if( $product->get_price() == 0 ) {
    unset($data[‘enabled’][‘ca’]);
    unset($data[‘enabled’][‘pr’]);
    }
    return $data;
    }
    add_filter( ‘woocommerce_variations_table_data’, ‘modify_variations_table_data’, 10, 1 );