Hook archive-product.php woocommerce (Overriding Issues) - php

I've tried all the solutions posted to StackOverflow and still no dice.
Woocommerce mentions that "archive-product" will not be able to be overwritten if you use woocommerce.php, so what is the correct way to loop woocommerce_content(); ? and still be able to edit archive-product? No matter what I do, I can't edit archive-product. I did have success with this, but this seems like bad practice;
if ( is_singular( 'product' ) ) {
woocommerce_content();
} else {
//For ANY product archive.
//Product taxonomy, product search or /shop landing
woocommerce_get_template( 'archive-product.php' );
}
Another solution most people find in function.php (which I already use)
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_theme_support('woocommerce');
I haven't seen anyone asking about this in my hours of research and would love some help.
This is very vague and basically just tells you that you can't edit the archive-product (without any solution of how to do so)
https://docs.woocommerce.com/document/template-structure/

Related

Activate WooCommerce Image Gallery and Modal on Archive Pages

I've scoured the internet and I know I can't be the only one. I've found this as a reference but it still does not work. I'm assuming it's because an older post and WooCommerce has changed: Activate Woocommerce image gallery features on shop archive page
I'm a bit familiar with WooCommerce so I thought I would be able to figure it out but I'm in over my head I think? I have a child theme. For the archive-product.php page I've updated the loop to pull the single-product template:
woocommerce_product_loop_start();
if ( wc_get_loop_prop( 'total' ) ) {
while ( have_posts() ) {
the_post();
/**
* Hook: woocommerce_shop_loop.
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'single-product' );
}
}
woocommerce_product_loop_end();
The page, with a little work, is essentially now what I need it to be:
The product image, no longer has the ability - like the gallery on an actual single-product page - to open in the lightbox modal. I'm assuming that's because the archive pages strip out that javascript. So I found another post: Activate Woocommerce image gallery features on shop archive page and that doesn't seem to work either. In the screenshot, you'll also notice the "Sizing Chart" which is supposed to open as a modal also, and not just list the information below it.
I'm at a loss and would love any help for anyone who has successfully done this. I wouldn't have thought it would be as difficult as it's proven to be, but here I am.

Removing the WooCommerce sidebar the correct way - TwentySeventeen?

I'm working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn't have a sidebar, WooCommerce seems to have it.
For example, the shop page has it - I have tried a few things already and none work without caveats or didn't work at all:
I tried copying archive-product.php to my theme dir in woocommerce/archive-product.php and removing the below:
do_action( 'woocommerce_after_main_content' );
This didn't work.
I then tried doing:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
...this didn't work either.
I found this answer and it worked, but didn't make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn't a great idea.
I also found this answer but it involves adding CSS, something I'd like to avoid as it isn't the most robust method in-case class names change in the future etc...
Isn't there a proper way of doing this without potential side affects?
Please, add this code to your functions.php
For remove only woocommerce side bar
function disable_woo_commerce_sidebar_mms() {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
add_action('init', 'disable_woo_commerce_sidebar_mms')
for remove all side bars
function remove_sidebar_mms() {
return false;
}
add_filter( 'is_active_sidebar', 'remove_sidebar_mms', 10, 2 );
OR
You can try this with to increase the priority hope fully its work
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',25);
With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:
// Remove the sidebar
add_action('get_header', 'blm_wc_remove_sidebar_check', 10);
// Removes the sidebar
function blm_wc_remove_sidebar($index) {
return false;
}
// Check to see if we're on a WooCommerce page and if so, remove the sidebar
function blm_wc_remove_sidebar_check() {
if ( is_woocommerce() ) {
add_filter('is_active_sidebar', 'blm_wc_remove_sidebar', 10, 1);
}
}
This avoids having to do the is_active_sidebar check / filter addition on non-WooCommerce pages.
Maybe there is a cleaner way to do this, but this worked for me.

Custom Layout for Single Product page - Woocommerce

I am trying to create a custom layout for one of our product pages in Woocommerce. I have searched and followed so many tutorials, but none are working for me. I copied 'single-product.php' and placed it into my active child theme in the folder 'woocommerce'. I then duplicated this and renamed it 'single-product-landing.php'.
I then placed the following code into my functions.php page:
add_filter( 'template_include', 'custom_single_product_template_include', 10 );
function custom_single_product_template_include( $template ) {
if ( is_product() && ( has_term( 'custom', 'product_cat') ) ) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-landing.php';
}
return $template;
}
Then I tried changing items in single-product-landing.php but nothing is changing, so it can't be picking it up. To confirm, I have the product assigned to the 'custom' category.
I should also add that my product is a 'variable' product, am not sure if that has any affect on anything here.
EDIT: I have found the following code in my 'single.php' file - I think this may be interfering. Problem is, if I delete this nothing shows on any of my pages (even those not affected by the new template):
<?php
if(get_theme_mod('product_layout') == 'custom') {
wc_get_template_part( 'content', 'single-product-custom' );
} else {
wc_get_template_part( 'content', 'single-product' );
}
?>
Any idea how I can modify this to still have content show but not over-rule the template change that i'm trying to make?
Page templates are loaded after the template_filter has been run, so adding that code to a page template file will have no effect. To make that run, place the same code in your child theme's functions.php.
The 566 at the end of the add_filter line refers to the filter's loading priority and not a category id. Simply put, the higher the number the later the filter will be loaded.
Finally, your if statement can be simplified a little using Woocommerce functions - if ( is_product() && ( has_term( 'custom', 'product_cat') ) ) { - doesn't make much difference, but it's tidier.

Wordpress Page and Custom Post

I'm having an irritating problem with my Wordpress site I was hoping you might be able to help me with.
Basically, I have a page - Case Studies, which was called 'case-studies' in the nav structure. It was later removed and re-added, forcing it to 'case-studies-2'. Is there any way of editing this? I tried changing the permalink within the page itself but it reverts to 'case-studies-2' after being changed.
My second issue is with the custom post type 'Case Study' which ties into this page. I can get the page to pull the custom posts in a list, but their permalink goes to a 404 and resetting the permalink structure didn't fix it!
Lastly, my attempts to resolve this problem have led to my Case Studies page bouncing back to the homepage no matter what I do with the template file.
Thanks in advance folks,
Graham
The first page of Case Study with nav-structure case-studies is still available in trash of post so firstly delete that page from trash & then edit your new case study page and in that edit permalink and remove 2 just like case-studies-2 to case-studies
For second issue you have to register your custom post type to theme's function.php file
For this add this code to function.php file
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'page', 'album', 'movies','music_review') );
return $query;
}
after this reset your permalink
Issue resolved - the old file was in the bin, not properly removed. Deleting it from there allowed me to update the permalink directly on the page :)
Thanks for your help, peeps!

woocommerce change continue shopping link in cart

I need to change the link for the "Continue Shopping" button in Wordpress WooCommerce. I have tried 6 different solutions that I found online, all of which involved editing the functions.php file using the hook woocommerce_continue_shopping_redirect.
None work and I have seen a few unanswered posts around the web with the same issue, which leads me to suspect that something has changed in the latest version of WP or WC.
Any ideas would be appreciated. Thanks.
You may try add below code into your theme functions.php:
function custom_woocommerce_continue_shopping_redirect( $return_to ) {
return get_permalink( woocommerce_get_page_id( 'shop' ) );
}
add_filter( 'woocommerce_continue_shopping_redirect', 'my_woocommerce_continue_shopping_redirect', 20);

Categories