Relocating product link in WooCommerce archives pages - php

The link I am trying to relocate is the link that wraps each product on the shop page which takes you to that products own page. As it is right now it wraps the image, product name, product sku and price. I only want it to wrap the image and product name.
Here's the code which is creating each product.
<li <?php post_class( $boot_classes ); ?>>
<?php
/**
* woocommerce_before_shop_loop_item hook.
*
* #hooked woocommerce_template_loop_product_link_open - 10
*/
do_action( 'woocommerce_before_shop_loop_item' );
/**
* woocommerce_before_shop_loop_item_title hook.
*
* #hooked woocommerce_show_product_loop_sale_flash - 10
* #hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
/**
* woocommerce_shop_loop_item_title hook.
*
* #hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item_title hook.
*
* #hooked woocommerce_template_loop_rating - 5
* #hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item hook.
*
* #hooked woocommerce_template_loop_product_link_close - 5
* #hooked woocommerce_template_loop_add_to_cart - 10
*/
do_action( 'woocommerce_after_shop_loop_item' );
?>
</li>
How is this possible?

You can change the location of the product link close as you expect, this way:
add_action('init', 'change_location_of_loop_product_link_close' );
function change_location_of_loop_product_link_close(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20 );
}
Code goes in function.php file of your active child theme (or active theme).
Tested and works.

Related

Woocommerce - How to put the short description beneath the product summary?

Using this as a visual reference for the hooks. I want to place the short summary at woocommerce_after_single_product_summary. I thought I could do that by simply doing something like this:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_excerpt',30);
This kind of works, but this places the short summary sort of on the product summary which messes up the whole layout. I've tried playing with priorities but nothing changes. I've also looked up the theme template file, but I can't figure out how to fix it. The theme template file:
<?php
defined( 'ABSPATH' ) || exit;
global $product;
/**
* Hook: woocommerce_before_single_product.
*
* #hooked wc_print_notices - 10
*/
do_action( 'woocommerce_before_single_product' );
if ( post_password_required() ) {
echo get_the_password_form(); // WPCS: XSS ok.
return;
}
?>
<div id="product-<?php the_ID(); ?>" <?php wc_product_class( '', $product ); ?>>
<?php
/**
* Hook: woocommerce_before_single_product_summary.
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
<div class="summary entry-summary ld-product-summary">
<?php
/**
* Hook: woocommerce_single_product_summary.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 20
* #hooked woocommerce_template_single_add_to_cart - 30
* #hooked woocommerce_template_single_meta - 40
* #hooked woocommerce_template_single_sharing - 50
* #hooked WC_Structured_Data::generate_product_data() - 60
*/
do_action( 'woocommerce_single_product_summary' );
?>
</div>
<?php
/**
* Hook: woocommerce_after_single_product_summary.
*
* #hooked woocommerce_output_product_data_tabs - 10
* #hooked woocommerce_upsell_display - 15
* #hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
</div>
<?php do_action( 'woocommerce_after_single_product' ); ?>
<?php
add_action('woocommerce_after_single_product_summary', 'show_short_description', 25);
function show_short_description() {
global $post;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
if( !empty($short_description) ) {
echo $short_description;
}
}

Add description to category page

Currently i'm a bit stuck at the category page.
I've created a page with the thumbnail and the category name.
Now, i'dd like to add the description of the category above the title.
The description of the category is shown on the page to choose the product, but i just can't get it on the category page.
Currently my code looks like this:
<div class="col-12 col-md-6 category_layer" <?php wc_product_cat_class( '', $category ); ?>>
<?php
/**
* woocommerce_before_subcategory hook.
*
* #hooked woocommerce_template_loop_category_link_open - 10
*/
do_action( 'woocommerce_before_subcategory', $category );
/**
* woocommerce_before_subcategory_title hook.
*
* #hooked woocommerce_subcategory_thumbnail - 10
*/
do_action( 'woocommerce_before_subcategory_title', $category );
/**
* woocommerce_shop_loop_subcategory_title hook.
*
* #hooked woocommerce_template_loop_category_title - 10
*/
do_action( 'woocommerce_shop_loop_subcategory_title', $category );
/**
* woocommerce_after_subcategory_title hook.
*/
do_action( 'woocommerce_after_subcategory_title', $category );
/**
* woocommerce_after_subcategory hook.
*
* #hooked woocommerce_template_loop_category_link_close - 10
*/
do_action( 'woocommerce_after_subcategory', $category ); ?>
</div
I'll guess i miss something when i'd like to add:
<?php
/**
* Hook: woocommerce_archive_description.
*
* #hooked woocommerce_taxonomy_archive_description - 10
* #hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
I tried to put it above:
#hooked woocommerce_template_loop_category_title -10
Is someone able to help me out?
Thank you so much!
You can try something like this :
add_action( 'woocommerce_after_subcategory_title', function($category){
echo '<p>' . category_description($category->id) . '</p>';
} );
I'm not sure about the $category->id, please check the object type, you need category (term id) as category_description() parameter, or any other way here to output the term description from $category parameter.

Move woocommerce category description below products

We are trying to get our product category descriptions to the bottom of the page so the products show first. I tried all the suggestions in this topic but none of them worked like they should.
The following piece of code places the category discription in three places, above the products, through the products and below the products.
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_after_main_content', 'woocommerce_taxonomy_archive_description', 100 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );
When I remove the middle line (about the main_content) the description that goes through the products disappears. So all I need to fix is removing the description for the top of the product page.
I would really appreciate your help. It might help to check out the product category on our website.
Code of my archive-product.php:
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author Transvelo
* #package WooCommerce/Templates
* #version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
electro_get_header(); ?>
<?php
/**
* woocommerce_before_main_content hook.
*
* #hooked electro_before_wc_content - 10 (outputs opening divs for the content)
* #hooked electro_before_product_archive_content - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
<?php
/**
* woocommerce_archive_description hook.
*
* #hooked woocommerce_taxonomy_archive_description - 10
* #hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
<?php if ( have_posts() ) : ?>
<?php
/**
* woocommerce_before_shop_loop hook.
*
* #hooked electro_product_subcategories - 0
* #hooked electro_wc_loop_title - 10
* #hooked electro_shop_control_bar - 10
* #hooked electro_reset_woocommerce_loop - 90
*/
do_action( 'woocommerce_before_shop_loop' );
?>
<?php
/**
* woocommerce_shop_loop hook
*
* #hooked electro_shop_loop
*/
do_action( 'woocommerce_shop_loop' );
?>
<?php
/**
* woocommerce_after_shop_loop hook.
*
* #hooked woocommerce_pagination - 10
*/
do_action( 'woocommerce_after_shop_loop' );
?>
<?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
<?php wc_get_template( 'loop/no-products-found.php' ); ?>
<?php endif; ?>
<?php
/**
* woocommerce_after_main_content hook.
*
* #hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
?>
<?php
/**
* woocommerce_sidebar hook.
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
?>
Add this code in function.php
add_action('woocommerce_archive_description', 'custom_archive_description', 2);
function custom_archive_description(){
if ( is_product_category() ){
remove_action('woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action('woocommerce_after_main_content', 'woocommerce_taxonomy_archive_description', 5 );
}
}
Source link
insert this function in the function.php of your theme. to activate the short code.
use the shortcode in the category page, the text enclosed in the short code will make the jump
[wcsaltasotto] text you want to jump below[/wcsaltasotto]
function salta_sotto_shortcode( $atts, $content = null ) {
$GLOBALS['salta_sotto_marco'] = '<div class="descrizione-due">' . $content . '<br></div><br>';
}
add_shortcode( 'wcsaltasotto', 'salta_sotto_shortcode' );
function funzione_salta_sotto_marco ( ){
if (isset($GLOBALS['salta_sotto_marco'])) {
echo $GLOBALS['salta_sotto_marco'] ;
}
}
add_action( 'woocommerce_after_shop_loop', 'funzione_salta_sotto_marco' );
Use this code in function.php
// move category description to bottom of pages
remove_action( 'woocommerce_archive_description',woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );

Moving the page title on archive-product page in WooCommerce

On my WooCommerce shop page (archive-product template), I'm trying to move the page title so that it is outside the site-inner area and rather in the header area, like it is on the other pages on my site. I want to add a full-width image behind it, so I need it outside the current hook that it's in.
I'd also like to be able to make this edit in my functions.php file so that I don't have to worry about WooCommerce upgrades.
Here's the code on the archive-product page that's controlling the title:
get_header( 'shop' ); ?>
<?php
/**
* woocommerce_before_main_content hook.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
<?php
/**
* woocommerce_archive_description hook.
*
* #hooked woocommerce_taxonomy_archive_description - 10
* #hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
What can I add to my functions.php to override where the page title is now? You can see the page in question here.
First, it's possible to Override WooCommerce templates via a Theme (better with a child theme) avoiding the problem of woocommerce updates.
To remove the WooCommerce archives pages title you can use the code below:
add_filter( 'woocommerce_show_page_title', '__return_false' );
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Then you will have to edit your header.php theme template to make the page title appear on the shop page just as you want (the best solution is to create a child theme and copy header.php from parent theme to child theme).
You can also use WooCommerce conditional tags to target the Shop page and other WooCommerce archives pages…
Copy wp-content\plugins\woocommerce\templates\archive-product.php
to wp-content\themes\your-theme\woocommerce\archive-product.php
Change code:
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
get_header( 'shop' );
/**
* Hook: woocommerce_before_main_content.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
* #hooked WC_Structured_Data::generate_website_data() - 30
*/
?>
<header class="woocommerce-products-header">
<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
<h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
<?php
/**
* Hook: woocommerce_archive_description.
*
* #hooked woocommerce_taxonomy_archive_description - 10
* #hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
</header>
<?php
do_action( 'woocommerce_before_main_content' );
if ( have_posts() ) {
/**
* Hook: woocommerce_before_shop_loop.
*
* #hooked wc_print_notices - 10
* #hooked woocommerce_result_count - 20
* #hooked woocommerce_catalog_ordering - 30
*/
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
if ( wc_get_loop_prop( 'total' ) ) {
while ( have_posts() ) {
the_post();
/**
* Hook: woocommerce_shop_loop.
*
* #hooked WC_Structured_Data::generate_product_data() - 10
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
}
woocommerce_product_loop_end();
/**
* Hook: woocommerce_after_shop_loop.
*
* #hooked woocommerce_pagination - 10
*/
do_action( 'woocommerce_after_shop_loop' );
} else {
/**
* Hook: woocommerce_no_products_found.
*
* #hooked wc_no_products_found - 10
*/
do_action( 'woocommerce_no_products_found' );
}
/**
* Hook: woocommerce_after_main_content.
*
* #hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
/**
* Hook: woocommerce_sidebar.
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
get_footer( 'shop' );

Display product price under the product image

In WooCommerce, I would like to display product varation price under image. I am using some code in my functions.php but not working please any help will be appreciated. Thanks
add_action( 'woocommerce_product_thumbnails','woocommerce_single_variation',30 );
For that you need to:
Remove the woocommerce_template_single_price in woocommerce_single_product_summary hook:
/**
* woocommerce_single_product_summary hook.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 20
* #hooked woocommerce_template_single_add_to_cart - 30
* #hooked woocommerce_template_single_meta - 40
* #hooked woocommerce_template_single_sharing - 50
*/
To add it in woocommerce_before_single_product_summary hook:
/**
* woocommerce_before_single_product_summary hook.
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
So your code will be:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_product_thumbnails','woocommerce_template_single_price', 30 );
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.

Categories