Select Page

Add WooCommerce parent category name as a class to body of child products

If you need to style category pages depending on category this will add the parent category name as a class into the body meaning that you can then target all child categories with a small amount of css.

<?php
//add woocommerce parent category name to body
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 > 0 ) {
            // 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' );
?>

Remove WooCommerce product meta

Use this to remove the WooCommerce product meta which including categories and sku’s

//remove product meta
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

Remove WooCommerce additional info tab from product page

Use this to remove WooCommerce additional info tab from product page.

<?php 
//remove additional info tab from products
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
    global $product;
	if( $product->has_attributes() || $product->has_dimensions() || $product->has_weight() ) {
        unset( $tabs['additional_information'] );
    }
    return $tabs;
}
?>

Woocommerce custom field under product title on product category page

Add Advanced Custom Field below the Woocommerce product title called ‘strapline’ on the product category page.
You can then style second-tile class to make it look different.

<?php 
//add cubtitle under product name
function nssecondtitle() { ?>
<div class="second-tile"><?php echo get_post_meta(get_the_ID(), "strapline", true); ?></div>
<?php }
add_action( 'woocommerce_after_shop_loop_item_title', 'nssecondtitle', 6 );
?>

Move WooCommerce long description, additional information and reviews under add to cart

This will move the WooCommerce long description, additional information and reviews to the right hand column under the add to cart button.

<?php 
// Move product tabs
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 60 );
?>

Remove WooCommerce Breadcrumbs

Add this to your functions file to remove WooCommerce breadcrumbs. You can then use something like ‘Yoast’ to add breadcrumbs to all pages/posts and products.

<?php 
//remove woo breadcrumb
add_action( 'init', 'jk_remove_wc_breadcrumbs' );
function jk_remove_wc_breadcrumbs() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
?>

How to grey out ‘out of stock’ products in WooCommerce

Add this to your functions files to grey out ‘out of stock’ products in WooCommerce

//grey out out of stock products
function grey_out_variations_when_out_of_stock( $grey_out, $variation ) {
    if ( ! $variation->is_in_stock() )
        return false;
    return true;
}

Add search to main WordPress menu

Add this to your functions file to add search to the main menu of your website.

<?php 
//add search to menu
function se_add_search_box_to_menu( $items, $args ) {
    if ( $args->theme_location === 'main' )
        return $items . get_search_form();

    return $items;
}
add_filter( 'wp_nav_menu_items', 'se_add_search_box_to_menu', 10, 2 );
?>

Change all PrestaShop products to show price

Using this command you can easily set all products to show the price.

UPDATE `ps_product` SET show_price =1 WHERE show_price =0
UPDATE `ps_product_shop` SET show_price =1 WHERE show_price =0

Archives