Modify the Data Fields of the Table

Filter & Hooks Viewed: 1128

If you want to enable or disable specific product data for the variations table you can use the “woocommerce_variations_table_data” filter like below.

In this example for the product ID 565 it has no price (pr), no add to cart (ca) and no sku (sk). Instead we added Stock (st) and Dimensions.

function modify_variations_table_data($data) {
	global $product;

	if($product->get_id() == 565) {
		unset($data['enabled']['pr']);
		unset($data['enabled']['ca']);
		unset($data['enabled']['sk']);
		$data['enabled']['st'] = 'Stock';
		$data['enabled']['di'] = 'Dimensions';
	}
    return $data;
}
add_filter( 'woocommerce_variations_table_data', 'modify_variations_table_data', 10, 1 );

Reference of Variables:

  • ‘im’ => Image
  • ‘sk’ => SKU
  • ‘pr’ => Price
  • ‘st’ => Stock
  • ‘at’ => Attributes
  • ‘ca’ => Add to Cart
  • ‘de’ => Description
  • ‘di’ => Dimensions
  • ‘we’ => Weight

8 thoughts on “Modify the Data Fields of the Table

  1. Luis Villagran says:

    Hi, i’m trying to add a custom download link at the end of every variation in the table. ¿How can i accomplish this? I need a column in the variation table that has a download link for every item. Is this possible?

  2. Cristian says:

    Could it be, for example, that in a line of the table, which is a variation, an image appears, and in other variations, no?

  3. Ivan says:

    Hello, I have made the filter to add the image to articles that I want, but it is added at the end of the table, is it possible to put it in the first column?

      • ivan says:

        Hello because I need it to appear in the first column. The first thing I did was add the image column in the plugin options, and remove that column in the products that I do not want to appear, but there are more products that I do not want to appear and few that do, so I opted for the option. adding the column, but I ran into the problem that adds it at the end, after the add to cart button, and I want the first column to be added, is it possible?

  4. ivan says:

    Hello, because I have products that must come out with the image column and others that don’t, but there are many more that do not come out with the image column, so I add that column with that code but the last one puts it, and I need the first one to appear , it’s possible?

Leave a Reply

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