Editing shop wrapper in child theme

The shop wrapper is found in /x/framework/functions/global/plugins/woocommerce.php

Copying this file structure to my child theme folder doesn’t overwrite this.

So ever time the theme updates, the changes I’ve made to the shop wrapper layout reverts.

What is the correct way to overwrite this with my child theme?

Hello @waterbarry,

Thanks for writing in! :slight_smile:

Can you share us your shop wrapper code?

You won’t be able to do any Woocomerce customizations via child theme. It will always be disregarded.

You can however make changes directly in Woocomerce by adding customizations on functions.php of your child theme.

Thank you.

Thanks for the reply @jumar

I’ve got the product category under the title like so:

// Title
// -----

function x_woocommerce_template_loop_product_title() {
  echo '<h3><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h3>';
  $categories = get_the_terms( get_the_ID(), 'product_cat' );
foreach ($categories as $category)
  echo '<div class="prod_cat_front"><h4> ' . $category->name . ' </h4></div>';
}

add_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_template_loop_product_title', 10 );
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );

I’m also inserting a secondary feature image, the primary one fades on a timer using javascript

// Shop Product Thumbnails
// -----------------------

function x_woocommerce_shop_product_thumbnails() {

  GLOBAL $product;

  $id     = get_the_ID();
  $thumb  = 'shop_catalog';
  $rating = ( function_exists( 'wc_get_rating_html' ) ) ? wc_get_rating_html( $product->get_average_rating() ) : $product->get_rating_html();
$feature2 = kdmfi_get_featured_image( 'featured-image-2');

  woocommerce_show_product_sale_flash();
  echo '<div class="entry-featured"';
  if ( ! empty( $feature2 ) ) {
  	echo 'style="background-image: url(';
  echo kdmfi_get_featured_image_src( 'featured-image-2', 'medium' );
  echo ');">';
  }
  else
  	{
  	echo 'style="background-image: url(';
  echo get_the_post_thumbnail_url( $id, $thumb );
  echo ');">';
  }
    echo '<a href="' . get_the_permalink() . '">';
      echo get_the_post_thumbnail( $id, $thumb );
	  if ( ! empty( $rating ) ) {
        echo '<div class="star-rating-container aggregate">' . $rating . '</div>';
      }
    echo '</a>';
  echo "</div>";

}

remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_shop_product_thumbnails', 10 );

And I’ve a Gender tag in the top right corner that’s put together with css and the category names

// Shop Item Wrapper
// -----------------

function x_woocommerce_before_shop_loop_item() {
  echo '<div class="entry-product">';
echo '<span class="prodcat';
 $categories = get_the_terms( get_the_ID(), 'product_cat' );
foreach ($categories as $category)
    echo ' ' . $category->name . '';
echo '" title=" ' . $category->name . ';';
echo '"> </span>';
}

function x_woocommerce_after_shop_loop_item() {
  echo '</div>';
}

function x_woocommerce_before_shop_loop_item_title() {
  echo '<div class="entry-wrap"><header class="entry-header">';
}

function x_woocommerce_after_shop_loop_item_title() {
  woocommerce_template_loop_add_to_cart();
  echo '</header></div>';
}

add_action( 'woocommerce_before_shop_loop_item', 'x_woocommerce_before_shop_loop_item', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'x_woocommerce_after_shop_loop_item', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'x_woocommerce_before_shop_loop_item_title', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'x_woocommerce_after_shop_loop_item_title', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

How do I go about replacing these via functions.php?

Hi,

You can change add_action to remove_action then add your own function.

eg. To override this code

// Title
// -----

function x_woocommerce_template_loop_product_title() {
  echo '<h3><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h3>';
  $categories = get_the_terms( get_the_ID(), 'product_cat' );
foreach ($categories as $category)
  echo '<div class="prod_cat_front"><h4> ' . $category->name . ' </h4></div>';
}

add_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_template_loop_product_title', 10 );
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );

You can add this in your child theme’s functions.php file

// Title
// -----

function myown_template_loop_product_title() {
  echo '<h3><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h3>';
  $categories = get_the_terms( get_the_ID(), 'product_cat' );
foreach ($categories as $category)
  echo '<div class="prod_cat_front"><h4> ' . $category->name . ' </h4></div>';
}

remove_action( 'woocommerce_shop_loop_item_title', 'x_woocommerce_template_loop_product_title', 10 );
add_action( 'woocommerce_shop_loop_item_title', 'myown_template_loop_product_title', 10 );

Hope that helps

Thanks for the reply @paul.r

The add_action in your code works, but the remove_action doesn’t

Is there something I’m missing?

Hi There,

Could you please paste your full code here so we can take a closer look?

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.