hook the product category links in, instead of hard coding into the template. #8575

This commit is contained in:
James Koster 2015-10-01 15:28:57 +01:00
parent fe689d3d24
commit 018bcc9d2d
3 changed files with 48 additions and 27 deletions

View File

@ -521,7 +521,7 @@ if ( ! function_exists( 'woocommerce_template_loop_subcategory_title' ) ) {
/** /**
* Show the subcategory title in the product loop. * Show the subcategory title in the product loop.
*/ */
function woocommerce_template_loop_subcategory_title( $category ) { function woocommerce_template_loop_category_title( $category ) {
?> ?>
<h3> <h3>
<?php <?php
@ -538,7 +538,7 @@ if ( ! function_exists( 'woocommerce_template_loop_subcategory_title' ) ) {
* Insert the opening anchor tag for products in the loop. * Insert the opening anchor tag for products in the loop.
*/ */
function woocommerce_template_loop_product_link_open() { function woocommerce_template_loop_product_link_open() {
echo '<a href="' . the_permalink() . '">'; echo '<a href="' . get_the_permalink() . '">';
} }
/** /**
* Insert the opening anchor tag for products in the loop. * Insert the opening anchor tag for products in the loop.
@ -546,6 +546,18 @@ function woocommerce_template_loop_product_link_open() {
function woocommerce_template_loop_product_link_close() { function woocommerce_template_loop_product_link_close() {
echo '</a>'; echo '</a>';
} }
/**
* Insert the opening anchor tag for categories in the loop.
*/
function woocommerce_template_loop_category_link_open( $category ) {
echo '<a href="' . get_term_link( $category->slug, 'product_cat' ) . '">';
}
/**
* Insert the opening anchor tag for categories in the loop.
*/
function woocommerce_template_loop_category_link_close() {
echo '</a>';
}
if ( ! function_exists( 'woocommerce_taxonomy_archive_description' ) ) { if ( ! function_exists( 'woocommerce_taxonomy_archive_description' ) ) {
/** /**

View File

@ -95,7 +95,11 @@ add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_produ
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
add_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_subcategory_title', 10 );
add_action( 'woocommerce_before_subcategory', 'woocommerce_template_loop_category_link_open', 10 );
add_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10 );
add_action( 'woocommerce_after_subcategory', 'woocommerce_template_loop_category_link_close', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );

View File

@ -35,11 +35,14 @@ if ( empty( $woocommerce_loop['columns'] ) ) {
$woocommerce_loop['loop'] ++; $woocommerce_loop['loop'] ++;
?> ?>
<li <?php wc_product_cat_class(); ?>> <li <?php wc_product_cat_class(); ?>>
<?php do_action( 'woocommerce_before_subcategory', $category ); ?>
<a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>">
<?php <?php
/**
* woocommerce_before_subcategory hook
*
* @hooked woocommerce_template_loop_category_link_open - 10
*/
do_action( 'woocommerce_before_subcategory', $category );
/** /**
* woocommerce_before_subcategory_title hook * woocommerce_before_subcategory_title hook
* *
@ -50,7 +53,7 @@ $woocommerce_loop['loop'] ++;
/** /**
* woocommerce_shop_loop_subcategory_title hook * woocommerce_shop_loop_subcategory_title hook
* *
* @hooked woocommerce_template_loop_subcategory_title - 10 * @hooked woocommerce_template_loop_category_title - 10
*/ */
do_action( 'woocommerce_shop_loop_subcategory_title', $category ); do_action( 'woocommerce_shop_loop_subcategory_title', $category );
@ -58,9 +61,11 @@ $woocommerce_loop['loop'] ++;
* woocommerce_after_subcategory_title hook * woocommerce_after_subcategory_title hook
*/ */
do_action( 'woocommerce_after_subcategory_title', $category ); do_action( 'woocommerce_after_subcategory_title', $category );
?>
</a> /**
* woocommerce_after_subcategory hook
<?php do_action( 'woocommerce_after_subcategory', $category ); ?> *
* @hooked woocommerce_template_loop_category_link_close - 10
*/
do_action( 'woocommerce_after_subcategory', $category ); ?>
</li> </li>