- This topic has 21 replies, 3 voices, and was last updated 1 year, 6 months ago by
Tom.
-
AuthorPosts
-
August 18, 2019 at 6:50 am #987128
ustar
Hello, there!
I’d like to add some additional information to the WC category page.
In another theme I redefined the file theme_name/woocommerce/layouts/category.php in the child theme.
But there is no such template in the parent theme Generatepress. Also, it is not in the Woocommerce plugin files.I’d like to add some code to display similar products on category pages with low count of products.
Wich template should i add to the Generatepress-child folder to add there my code?
Best regarsd, Sergey.
August 18, 2019 at 8:47 am #987323David
StaffCustomer SupportHi there,
the woo templates can be found here, there is no longer a specific category template just the archive-product template:
https://github.com/woocommerce/woocommerce/tree/master/templates
You may want to look at using Hooks to add your custom content instead of rewriting your own template.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 18, 2019 at 9:09 am #987335ustar
Hi, David!
Yes, maybe hook is it really good idea.
I’ll try this today and let you know.Thanks for advice!
Best Wishes, Sergey.
August 18, 2019 at 9:12 am #987339David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 20, 2019 at 5:28 am #988739ustar
Hi, David!
I have tried to use hook, but i’m not sure that i use a right code around.
I see info where the hook should be shown, but there only code displaying.
So, i soppouse, hook is working, but not working code inside the hook.Can i sent to you this code privately to have a look?
Regards, Sergey.
August 20, 2019 at 6:34 am #988789David
StaffCustomer SupportWhat type of code is it?
If it is PHP or a Shortcode then you need to check Enable PHP / Enable Shortcodes in the Hook Element.Let us know.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 20, 2019 at 6:58 am #988815ustar
I soppouse this is php code wich show additional product block with 9 products on woocommerce category page, when this current category contains less then 10 products.
Example, how it should be here:
https://u-star.cz/boty/fialova/I have used this code for the hook:
<?php
if ( fl_woocommerce_version_check( ‘3.4.0’ ) ? woocommerce_product_loop() : have_posts() ) {
/**
* Hook: woocommerce_before_shop_loop.
*
* @hooked wc_print_notices – 10
* @hooked woocommerce_result_count – 20 (FL removed)
* @hooked woocommerce_catalog_ordering – 30 (FL removed)
*/
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();
global $wp_query;
$globalTaxQuery = $wp_query->query_vars[‘tax_query’];
$isFilterUse = count($globalTaxQuery) > 2;
$productIds = array_map(function ($product)
{
return $product->ID;
}, $wp_query->posts);if (is_tax(‘product_cat’)) {
$queriedObject = get_queried_object();if (wc_get_loop_prop( ‘total’ ) < 10 && $queriedObject->parent != 0) {
$args = [
‘post_type’ => ‘product’,
‘posts_per_page’ => 9,
‘tax_query’ => [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $queriedObject->parent,
],
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $queriedObject->term_id,
‘operator’ => ‘NOT IN’
]
],
‘meta_query’ => [
[
‘key’ => ‘_stock_status’,
‘value’ => ‘instock’
]
]
];if ($isFilterUse) {
unset($globalTaxQuery[‘relation’]);$args[‘tax_query’] = [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $queriedObject->term_id
]
];
$args[‘post__not_in’] = $productIds;/*foreach ($globalTaxQuery as $key => $value) {
if ($value[‘taxonomy’] == ‘product_visibility’) {
continue;
}$value[‘operator’] = ‘NOT IN’;
$args[‘tax_query’][] = $value;
}*/
}$loop = new WP_Query( $args );
if ($isFilterUse && $loop->post_count < 9) {
$args = [
‘post_type’ => ‘product’,
‘posts_per_page’ => 9,
‘tax_query’ => [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $queriedObject->parent,
],
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $queriedObject->term_id,
‘operator’ => ‘NOT IN’
]
],
‘meta_query’ => [
[
‘key’ => ‘_stock_status’,
‘value’ => ‘instock’
]
]
];$loop = new WP_Query( $args );
}if ($loop->post_count < 9) {
$currentCat = $queriedObject;
$prevCat = $queriedObject;while ($loop->post_count < 9) {
if ($currentCat->parent == 0) {
$args = [
‘post_type’ => ‘product’,
‘posts_per_page’ => 9,
‘tax_query’ => [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘name’,
‘terms’ => ‘Boty’
]
],
‘meta_query’ => [
[
‘key’ => ‘_stock_status’,
‘value’ => ‘instock’
]
]
];$loop = new WP_Query( $args );
break;
}$currentCat = get_term($currentCat->parent, ‘product_cat’);
$args = [
‘post_type’ => ‘product’,
‘posts_per_page’ => 9,
‘tax_query’ => [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $currentCat->term_id,
],
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $prevCat->term_id,
‘operator’ => ‘NOT IN’
]
],
‘meta_query’ => [
[
‘key’ => ‘_stock_status’,
‘value’ => ‘instock’
]
]
];$loop = new WP_Query( $args );
$prevCat = $currentCat;
}
}if ( $loop->have_posts() ) {
echo ‘<h2>Zbývající produkty našeho katalogu</h2>’;
woocommerce_product_loop_start();
while ($loop->have_posts() ) {
$loop->the_post();
wc_get_template_part( ‘content’, ‘product’ );
}woocommerce_product_loop_end();
} else {
//echo __( ‘No products found’ );
}wp_reset_postdata();
} else if (wc_get_loop_prop( ‘total’ ) < 10) {
$args = [
‘post_type’ => ‘product’,
‘posts_per_page’ => 9,
‘tax_query’ => [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘name’,
‘terms’ => ‘Boty’
]
],
‘meta_query’ => [
[
‘key’ => ‘_stock_status’,
‘value’ => ‘instock’
]
]
];if ($isFilterUse) {
unset($globalTaxQuery[‘relation’]);$args[‘tax_query’] = [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘terms’ => $queriedObject->term_id
]
];
$args[‘post__not_in’] = $productIds;/*foreach ($globalTaxQuery as $key => $value) {
if ($value[‘taxonomy’] == ‘product_visibility’) {
continue;
}$value[‘operator’] = ‘NOT IN’;
$args[‘tax_query’][] = $value;
}*/
}$loop = new WP_Query( $args );
if ($isFilterUse && $loop->post_count < 9) {
$args = [
‘post_type’ => ‘product’,
‘posts_per_page’ => 9,
‘tax_query’ => [
‘relation’ => ‘AND’,
[
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘name’,
‘terms’ => ‘Boty’
]
],
‘meta_query’ => [
[
‘key’ => ‘_stock_status’,
‘value’ => ‘instock’
]
]
];$loop = new WP_Query( $args );
}if ( $loop->have_posts() ) {
echo ‘<h2>Zbývající produkty našeho katalogu</h2>’;
woocommerce_product_loop_start();
while ($loop->have_posts() ) {
$loop->the_post();
wc_get_template_part( ‘content’, ‘product’ );
}woocommerce_product_loop_end();
} else {
//echo __( ‘No products found’ );
}wp_reset_postdata();
}
}/**
* 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’ );
}
?>But, when i mark Execute PHP in settings of the hook, it braking the site.
Looks like i’m mistaken somewhere.Regards, Sergey.
August 20, 2019 at 5:05 pm #989293Tom
Lead DeveloperLead DeveloperHi there,
Where did you get this code, exactly? For example, where does the
fl_woocommerce_version_check()
function come from?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 20, 2019 at 10:20 pm #989367ustar
Hello, Tom.
This is part of code from category.php of the previews theme.
Can i send this file to you somehow privately?Regards, Sergey.
August 21, 2019 at 2:23 am #989464ustar
I realised! This is from Flatsome theme.
It is costomised template category.php
How i can sand to you this file?Regards, Sergey.
August 21, 2019 at 9:11 am #989891Tom
Lead DeveloperLead DeveloperIs there a specific error you encounter when you try to use the template?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 21, 2019 at 10:14 am #989942ustar
Hey, Tom!
I think hook works, because hook displaying an additional onfo, but function insode the hook wich i put inside, doesn’t.
Because i see code like a text istead an additional product block:
query_vars[‘tax_query’]; $isFilterUse = count($globalTaxQuery) > 2; $productIds = array_map(function ($product) { return $product->ID; }, $wp_query->posts); if (is_tax(‘product_cat’)) { $queriedObject = get_queried_object(); if (wc_get_loop_prop( ‘total’ ) < 10 && $queriedObject->parent != 0) { $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 9, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $queriedObject->parent, ], [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $queriedObject->term_id, ‘operator’ => ‘NOT IN’ ] ], ‘meta_query’ => [ [ ‘key’ => ‘_stock_status’, ‘value’ => ‘instock’ ] ] ]; if ($isFilterUse) { unset($globalTaxQuery[‘relation’]); $args[‘tax_query’] = [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $queriedObject->term_id ] ]; $args[‘post__not_in’] = $productIds; /*foreach ($globalTaxQuery as $key => $value) { if ($value[‘taxonomy’] == ‘product_visibility’) { continue; } $value[‘operator’] = ‘NOT IN’; $args[‘tax_query’][] = $value; }*/ } $loop = new WP_Query( $args ); if ($isFilterUse && $loop->post_count < 9) { $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 9, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $queriedObject->parent, ], [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $queriedObject->term_id, ‘operator’ => ‘NOT IN’ ] ], ‘meta_query’ => [ [ ‘key’ => ‘_stock_status’, ‘value’ => ‘instock’ ] ] ]; $loop = new WP_Query( $args ); } if ($loop->post_count < 9) { $currentCat = $queriedObject; $prevCat = $queriedObject; while ($loop->post_count < 9) { if ($currentCat->parent == 0) { $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 9, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘name’, ‘terms’ => ‘Boty’ ] ], ‘meta_query’ => [ [ ‘key’ => ‘_stock_status’, ‘value’ => ‘instock’ ] ] ]; $loop = new WP_Query( $args ); break; } $currentCat = get_term($currentCat->parent, ‘product_cat’); $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 9, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $currentCat->term_id, ], [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $prevCat->term_id, ‘operator’ => ‘NOT IN’ ] ], ‘meta_query’ => [ [ ‘key’ => ‘_stock_status’, ‘value’ => ‘instock’ ] ] ]; $loop = new WP_Query( $args ); $prevCat = $currentCat; } } if ( $loop->have_posts() ) { echo ‘
Zbývající produkty našeho katalogu
‘; woocommerce_product_loop_start(); while ($loop->have_posts() ) { $loop->the_post(); wc_get_template_part( ‘content’, ‘product’ ); } woocommerce_product_loop_end(); } else { //echo __( ‘No products found’ ); } wp_reset_postdata(); } else if (wc_get_loop_prop( ‘total’ ) < 10) { $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 9, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘name’, ‘terms’ => ‘Boty’ ] ], ‘meta_query’ => [ [ ‘key’ => ‘_stock_status’, ‘value’ => ‘instock’ ] ] ]; if ($isFilterUse) { unset($globalTaxQuery[‘relation’]); $args[‘tax_query’] = [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => $queriedObject->term_id ] ]; $args[‘post__not_in’] = $productIds; /*foreach ($globalTaxQuery as $key => $value) { if ($value[‘taxonomy’] == ‘product_visibility’) { continue; } $value[‘operator’] = ‘NOT IN’; $args[‘tax_query’][] = $value; }*/ } $loop = new WP_Query( $args ); if ($isFilterUse && $loop->post_count < 9) { $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 9, ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘name’, ‘terms’ => ‘Boty’ ] ], ‘meta_query’ => [ [ ‘key’ => ‘_stock_status’, ‘value’ => ‘instock’ ] ] ]; $loop = new WP_Query( $args ); } if ( $loop->have_posts() ) { echo ‘
Zbývající produkty našeho katalogu
‘; woocommerce_product_loop_start(); while ($loop->have_posts() ) { $loop->the_post(); wc_get_template_part( ‘content’, ‘product’ ); } woocommerce_product_loop_end(); } else { //echo __( ‘No products found’ ); } wp_reset_postdata(); } } /** * 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’ ); } ?>And no errors in browser console.
Regards, Sergey.
August 21, 2019 at 4:26 pm #990154Tom
Lead DeveloperLead DeveloperAnd “Execute PHP” is checked? It’s super difficult to debug all of that code in the forum, unfortunately.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 23, 2019 at 6:00 am #991501ustar
So I’m using the support forum, isn’t it?
What to do?regards, Sergey.
August 23, 2019 at 6:06 am #991504ustar
Hi Tom.
I seem to get excited and wrote not about that))
Of course, my question does not concern the quality of the theme. I just wanted to ask for advice on how best to deal with my situation.
Regards, Sergey.
-
AuthorPosts
- You must be logged in to reply to this topic.