Which template file woocommerce is calling for product shortcode? - wordpress

I am using this shortcode [products limit="4"] to show the products on a different page called Theme.
Now I want to change the layout style of this Theme page by overriding woocommerce template file.
1) Which template file woocommerce is calling for this shortcode?
2) Can you give me a full reference where I can find which template file is responsive for which shortcode?
Regards.

Every shortcode related to product listing is calling template named content-product.php via follows -
// Render product template.
wc_get_template_part( 'content', 'product' );
You can find it here

Related

Show Woocommerce breadcrumbs on Category page

I am using the most current version of Woocommerce. I have breadcrumbs showing on a product page, but I want these displayed on a Category page also. Is there a hook for this? or do I need to edit a template file?
Add following code somewhere in your theme php files:
<?php woocommerce_breadcrumb(); ?>

Show default page template for product categories in Woocommerce

I'm having a problem with WooCommerce / Wordpress templates. I used to have everything working.
I have this code in my functions.php file:
add_filter( 'template_include', 'wpse138858_woocommerce_category_archive_template' );
function wpse138858_woocommerce_category_archive_template( $original_template ) {
if ( is_product_category() ) {
return get_template_directory().'/woocommerce/archive-product.php';
} else {
return $original_template;
}
}
This code chose my custom archive template for product categories and shop the main page. Suddenly, it's not working anymore. It seems like WordPress cannot use custom files from wp-content/themes/mytheme/woocommerce anymore. Single product page and product categories use page.php for some reason. I fixed an issue with single product page by creating file single-product.php on my theme folder. This works okay but I can't do the same with Woocommerce archive pages.
All archive pages uses page.php. They don't have pageId and I print out var_dump(is_product_category()); on some product category page, result is false.
Is there any way to force product categories to use archive-product.php template? How is it possible that category (archive) page uses page.php template?
Add add_theme_support( 'woocommerce' ); in your theme functions.php file. After this all WooCommerce templates will work as expected ( provided that the structure of the templates is correct ).

Is there some way to insert custom archive loop to any theme from plugin?

I'm coding plugin that create custom post type with custom fields. Now I need to build custom archive/category/tag templates which should contain custom fields.
The problem is that I couldn't insert template part inside archive loop from plugin.
Is there some hook to insert custom loop inside activated theme? Something like this:
add_filter('the_content', 'change_content_in_single_post');
Now I'm using this hook:
add_filter( 'template_include', 'change_whole_cpt_archive_template' );
... but when I use template_include hook it changes whole template and I need to do something like the_content filter. That hook get template of current theme and replace standart content template with my custom template - make it part of activated theme. It makes my CPT single page template compatible with any wp theme. Now I need to replace standart archive loop with my custom loop. For example: on archive page show posts without images... It must be something that replace result of standard get_template_part() function with custom template from plugin. That's what I`m searching for...
Anyway, maybe you know some better ways to make plugin (archive template) compatible with wp themes?
Huge thanks for any help!
you need to introduce some logic to only run on your cpt archive page.
add_filter( 'template_include', 'change_all_archive_template' );
function change_all_archive_template($template){
if ( is_post_type_archive('cptname') ) {
$template= 'find the template!';
//if( file_exists ) --> look in theme 1st??
//else --> load from plugin..
}
return $template;
}
There are quite a few plugins that use this technique to look in the active theme 1st and if not found, find the file in your plugin.
I found solution in woocommerce plugin files.
So... the best way to build custom archive template from plugin is to use template_include hook and in custom template file set header and footer from activated theme:
<?php get_header();
// custom archive loop
get_footer(); ?>
To make it more compatible with any wp themes use stanard wordpress and bootstrap classes.

woo commerce - how to show custom fields on published page

I have set 2 custom fields on the wordpress / woocommerce product page called "imballo" and "sottoimballo" with their values. How do I display these on the published page?
Thanks!
You would have to display the custom fields in the WooCommerce Single Product Page template,
You could do it in two ways,
Add a code in an existing hook of the Product Single page. Check hooks here
Modify the template by overriding it in your WordPress theme. Read here
And in the place where you want to display do the following,
<?php
//Please add your HTML structure as needed.
echo get_post_meta(get_the_ID(), 'imballo');
echo get_post_meta(get_the_ID(), 'sottoimballo');
?>

How to make a wordpress theme woocommerce compatible?

How can I make a wordpress theme woocommerce compatible ? I want to make cart page, my account page, product loop page, product single page,checkout page design into my wordpress theme.
We Can make WordPress theme compatible with woocommerce here is how you can do that
There are two ways to resolve this:
1] Using woocommerce_content() -
This solution allows you to create a new template page within your theme that will be used for all WooCommerce taxonomy and post type displays.
To set up this template page, perform the following steps:
Duplicate page.php-
Duplicate your theme’s page.php file, and name it woocommerce.php. This file should be found like this: wp-content/themes/YOURTHEME/woocommerce.php.
Edit your page (woocommerce.php)-
Open up your newly created woocommerce.php in a text editor, or the editor of your choice.
Replace the loop-
In woocommerce.php, replace the Loop with woocommerce_content();
i.e., instead of if(have_posts)… endif; should be replaced by
woocommerce_content()
This will ensure that the WooCommerce templates are picked up for the product and taxonomy pages.
2] Using WooCommerce Hooks-
The hook method is more involved that using woocommerce_content, but is more flexible. This is similar to the method we use when creating our themes. By inserting a few lines in your theme’s functions.php file, First unhook the WooCommerce wrappers;
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
Then hook in your own functions to display the wrappers your theme requires:
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10); function my_theme_wrapper_start() {
echo '<section id="main">';} function my_theme_wrapper_end() {
echo '</section>';}
3] Declare WooCommerce support -
Now that you have made the changes, the final thing you have to do, is specify that your theme now supports WooCommerce. You need to add the following in functions.php of your theme.
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
To make it more practical for you this is the video for you, which you
can follow too- How To Make WordPress Theme Compatible With WooCommerce Plugin
You need to install WooC and look at the all the style tags that come accross with it then you can style up the pages and add all of that to your style sheet.
Also you can use hooks but Im not 100% sure how you would check if WooC is active off the top of my head so that hooks in your code only come up when the plugin is active.

Resources