Add description to category page - php

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.

Related

How to Disable Single Product Page in WooCommerce

I am building an e-commerce site with Woocommerce 3.6.4 + Wordpress 5.2.2.
I tried to disable the single product page of WooCommerce so that people can shop directly from my shop page.
Tried:
1. Add the code below to my child theme's functions.php file, didn't work.
remove_action( ‘woocommerce_before_shop_loop_item’,‘woocommerce_template_loop_product_link_open’, 10 );
remove_action( ‘woocommerce_after_shop_loop_item’,‘woocommerce_template_loop_product_link_close’, 5 );
2. Add the same code to my WooCommerce content-product.php file. Didn't work.
3./wp-content/plugins/woocommerce/templates/content-product.php
Make these code as comments:
do_action( ‘woocommerce_before_shop_loop_item’);
do_action( ‘woocommerce_after_shop_loop_item’);
Become like this:
//do_action( ‘woocommerce_before_shop_loop_item’);
//do_action( ‘woocommerce_after_shop_loop_item’);
It removed the link to the shopping page, but didn't remove the single product page.
Any advice or help, please?
As a person who knows nothing about coding, this is literally driving me crazy!!!
Can anyone help me, please? Any suggestion would be great!!
Below is the wp_content/themes/my_theme/woocommerce/content-product.php:
`<?php
/**
* The template for displaying product content within loops
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-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.6.0
*/
defined( 'ABSPATH' ) || exit;
`
<li <?php wc_product_class( '', $product ); ?> data-product-id="<?php the_ID(); ?>">
<?php
/**
* Hook: woocommerce_before_shop_loop_item.
*
* #hooked woocommerce_template_loop_product_link_open - 10
*/
do_action( 'woocommerce_before_shop_loop_item' );?>
<?php if ('yes' != $themify->hide_product_image) : ?>
<?php
/**
* Hook: woocommerce_before_shop_loop_item_title.
*
* #hooked woocommerce_show_product_loop_sale_flash - 10
* #hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
?>
<?php endif; ?>
<div class="product-content">
<div class="product-content-inner-wrapper">
<div class="product-content-inner">
<?php
/**
* Hook: woocommerce_shop_loop_item_title.
*
* #hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' );
/**
* Hook: woocommerce_after_shop_loop_item.
*
* #hooked woocommerce_template_loop_product_link_close - 5
* #hooked woocommerce_template_loop_add_to_cart - 10
*/
do_action( 'woocommerce_after_shop_loop_item' );
?>
<div class="product-share-wrap">
<?php Themify_Wishlist::button() ?>
<?php if (themify_hide_quick_look()): ?>
<a onclick="return false;" data-image="<?php echo wc_placeholder_img_src() ?>" class="quick-look themify-lightbox" href="<?php echo add_query_arg(array('post_in_lightbox' => '1'), get_permalink()) ?>"><span class="tooltip"><?php _e('Quick Look', 'themify'); ?></span></a>
<?php endif; ?>
<?php if (themify_hide_social_share()): ?>
<?php get_template_part('includes/social-share', 'product'); ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- /.summary -->
</li>
In your themes functions.php add the code,
// remove single product page link
remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item','woocommerce_template_loop_product_link_close', 5 );
// hide single product page completely
add_filter( 'woocommerce_register_post_type_product','hide_product_page',12,1);
function hide_product_page($args){
$args["publicly_queryable"]=false;
$args["public"]=false;
return $args;
}
solution was partly based on #Vitaly Gritsienko 's answer

How to filter products on a Product category page with FacetWP

I want to add filters to my WooCommerce product category page. I'm using the FacetWP-plugin. I've added some code to my archive-product.php and I have gotten my filters to show on the page (which is as how I want it) but once I try to filter through the products - nothing is happening.
I've followed the following guide https://elvtn.com/wordpress-plugins/building-product-filter-woocommerce-facetwp/
I've also changed the following to True.
FacetWP - settings - WooCommerce - Support product variations? - True
Facets are also indexed correctly as the categories are showing up on the page but it's not actually filtering anything.
<div><div class="facetwp-template">
<?php if ( have_posts() ) : ?>
<?php
/**
* woocommerce_before_shop_loop hook.
*
* #hooked wc_print_notices - 10
* #hooked woocommerce_result_count - 20
* #hooked woocommerce_catalog_ordering - 30
*/
do_action( 'woocommerce_before_shop_loop' );
?>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/**
* woocommerce_shop_loop hook.
*
* #hooked WC_Structured_Data::generate_product_data() - 10
*/
do_action( 'woocommerce_shop_loop' );
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?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
/**
* woocommerce_no_products_found hook.
*
* #hooked wc_no_products_found - 10
*/
do_action( 'woocommerce_no_products_found' );
?>
<?php endif; ?>
</div></div>
<?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' );
?>
I expect that I should be able to filter through my products when I click on the checkbox but this is not happening

Relocating product link in WooCommerce archives pages

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.

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' );

Categories