• The Facebook Platform

Results 1 to 1 of 1
  1. #1
    Join Date
    Jan 2010
    Location
    Lahore, Pakistan
    Age
    25
    Posts
    3,818
    Points
    6,772.51
    Rep Power
    10000

    Default Add Woocommerce parent category to WP body class

    Here's a quick solution if you want to add WooCommerce parent category name as class in your WordPress theme's body.

    Step 1:
    Edit your theme's "functions.php" file

    Step 2:
    Put this code at the end of the file

    PHP Code:
    function woo_custom_taxonomy_in_body_class$classes ){
        
    $custom_terms get_the_terms(0'product_cat');
        if (
    $custom_terms) {
          foreach (
    $custom_terms as $custom_term) {

            
    // Check if the parent category exists:
            
    if( $custom_term->parent ) {
                
    // Get the parent product category:
                
    $parent get_term$custom_term->parent'product_cat' );
                
    // Append the parent class:
                
    if ( ! is_wp_error$parent ) )
                    
    $classes[] = 'product_parent_cat_' $parent->slug;   
            }

            
    $classes[] = 'product_cat_' $custom_term->slug;
          }
        }
        return 
    $classes;
    }

    add_filter'body_class''woo_custom_taxonomy_in_body_class' ); 






    Last edited by Їийоcёйт Кїllєґ; 10-11-2014 at 02:27 AM.
    Find Me On Social Networks

    Facebook | Twitter | Google+



 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •