Title: Variable product class name
Last modified: May 27, 2022

---

# Variable product class name

 *  Resolved [mnahmed](https://wordpress.org/support/users/mnahmed/)
 * (@mnahmed)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-class-name/)
 * Hello. How to target only product pages that have variations with CSS? .single-
   product doesn’t seem to work. I need to change styling of something that should
   be applied only on variable products pages. Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Support [Kaushik S. a11n](https://wordpress.org/support/users/kaushiksomaiya/)
 * (@kaushiksomaiya)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-class-name/#post-15683862)
 * Hi there!
 * Thanks for contacting us!
 * I understand you would like to style variable product pages with CSS.
 * If you are looking to style elements within the product information area – you
   could use the CSS class – `product-type-variable`
 * ![](https://d.pr/i/uMY8mH+)
 * If you’d like to style any element on the variable product page – You can try
   adding the snippet below in your theme’s functions.php file.
 *     ```
       add_filter( 'body_class', function ( $classes ) {
       if ( ! is_admin() && is_product() ) {
       global $post;
       $product = wc_get_product( $post->ID );
       $cssclass = 'my_class_'.$product->get_type();
       	return array_merge( $classes, array( $cssclass ) );
       }
       else{
       	return $classes;
       }
       });
       ```
   
 * This would add a CSS class called `my_class_variable` to `<body>` element of 
   variable products. The code also works for any other product type.
 * I hope this helps! 🙂
 *  Thread Starter [mnahmed](https://wordpress.org/support/users/mnahmed/)
 * (@mnahmed)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-class-name/#post-15683923)
 * I went with the snippet and it worked. Thanks so much
 *  [Luminus Alabi](https://wordpress.org/support/users/luminus/)
 * (@luminus)
 * Automattic Happiness Engineer
 * [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-class-name/#post-15684938)
 * Hey [@mnahmed](https://wordpress.org/support/users/mnahmed/),
 * I’m happy to hear that you’ve got this sorted now.
 * I’ll go ahead and mark this thread as resolved.
 * Take care and have an amazing weekend ahead.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Variable product class name’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [Luminus Alabi](https://wordpress.org/support/users/luminus/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/variable-product-class-name/#post-15684938)
 * Status: resolved