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;
}

3 thoughts on “Modify Variations Table DataTables Options

    • Jukka says:

      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 );

Leave a Reply

Your email address will not be published. Required fields are marked *