So, in my page.php (and other template pages) I have a hero section with a background image and the title of the page. Then, following that, a section where the content goes (with ) all that is inside the loop.
To add WooCommerce functionality I added the below code, as per the official documentation:
// WooCommerce Integration
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
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 class="page-content large-padding shop-container">';
echo '<div class="grid-container">';
echo '<div class="grid-x">';
echo '<div class="cell entry-content" id="woocom">';
}
function my_theme_wrapper_end() {
echo '</div>';
echo '</div>';
echo '</div>';
echo '</section>';
}
The problem is that, yes, the products appear on the products page and the header and the footer appear, but the previous section (the hero image and title) don't.
What am I doing wrong?
Edit: Here's my page.php code:
<?php get_header(); ?>
<?php while (have_posts()): the_post(); ?>
<section class="page-hero text-center background" style="background-image:url(<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '1600×1000', false ); echo $src[0]; ?>);">
<div class="grid-container vertically-aligned">
<div class="grid-x justify-center">
<div class="cell large-9">
<h1 class="m-0"><?php the_title(); ?></h1>
</div>
</div>
</div>
</section>
<section class="page-content large-padding">
<div class="grid-container">
<div class="grid-x">
<div class="cell entry-content">
<?php the_content(); ?>
</div>
</div>
</div>
</section>
<?php endwhile; ?>
<?php get_footer(); ?>
In any case, I've been able to add that section modifying the archive-product.php template from woocommerce. The issue here is that because it's an archive page it doesn't get the attached image to add on the header but the image of the first listed product... is there a way to get the attached image of the Products page?
Related
I need to remove a filter that sets the template of my results, in this case, it uses UL to organize the content. I don't need this.
Case 1) Remove this and my code takes care os the layout
Case 2) Apply another filter to set my own template.
woocommerce/includes/widgets/class-wc-widgets-products.php
line 192
echo apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' );
line 199
echo apply_filters( 'woocommerce_after_widget_product_list', '</ul>');
There is another element that comes from the hook, but this one I couldn't found the place it comes from, my rendered html shows it:
<div class="listaprodutos"><h2 class="widgettitle">Produtos</h2>
<ul class="product_list_widget">
My goal is remove all these two settings (widgettitle and product_list_widget).
I add this lines in my functions.php page, but it didn't work:
// Remove UL format for products_widget
remove_filter( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' );
remove_filter( 'woocommerce_after_widget_product_list', '</ul>' );
front-page.php
<p class="display-4" style="text-align:center">Produtos mais vendidos</p>
<div class="container">
<?php if ( is_active_sidebar( 'listaprodutos' ) ) : ?>
<?php dynamic_sidebar( 'listaprodutos' ); ?>
<?php endif; ?>
</div>
content-widget-product.php
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card" style="width: 19rem; margin-bottom:3rem; margin-top:3rem;">
<img class="card-img-top img-fluid" src=<?php echo $product->get_image(); ?>
<div class="card-block">
<h4 class="card-title"><?php echo $product->get_name(); ?></h4>
<p class="card-text">
<?php echo $product->get_price_html(); ?>
</p>
<a class="btn btn-quick" href="<?php echo esc_url( $product->get_permalink() ); ?>">Ler o post</a>
</div>
</div>
</div>
</div>
I am a beginner in wordpress and I tried all the ways but I cannot make my theme woocommerce supportable. Below is my page.php
page.php
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
*/
?>
<?php get_header(); ?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="page">
<?php if ( have_posts() ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<div class="post">
<h3 class="<?php post_class(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
At first I duplicate page.php and create woocommerce.php and upload to server, but it fails, below is my woocommerce.php
woocommerce.php
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
*/
?>
<?php get_header(); ?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="page">
<?php woocommerce_content(); ?>
</div>
</div>
<?php get_footer(); ?>
But it fails, after this I deleted woocommerce.php from server and edited my functions.php file to add woocommerce supportable code. Below is the code I added in my functions.php file.
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
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 '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><div class="page">';
}
function my_theme_wrapper_end() {
echo '</div></div>';
}
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
but it also fails, you can see the output here
If you see in debugger you can see that no woocommerce css file has been loaded.
Please help me with your suggestion. Thank you.
go to functions.php and add this at the top,
add_theme_support('woocommerce');
most preferably at an initialisation function.
So I'm making a one-page-site for a client, which includes a webshop. Now each WP-pages makes up a slide. The slides uses different theme-templates and in one of the slides called "Shop" I want to display all WooCommerce-products (it uses the template slide-shop.php .
Right now the <ul class="products"> is echoed, however the content of it is empty. If you go to the page url (site.com/shop) all products show fine.
one-page.php:
<?php
$pages = get_pages(array('sort_column' => 'menu_order'));
$i = 0;
foreach ($pages as $page_data) {
$page_ID = $page_data->ID;
//$slug = $page_data->post_name;
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$template = get_page_template_slug( $page_ID );
$i++;
?>
<section id="slide-<?php echo $i; ?>" class="slide cf">
<div class="slide-wrap cf">
<div class="slide-con item cf" >
<?php include($template); ?>
</div>
</div>
</section>
<?php
} /*end foreach*/
?>
slide-shop.php:
/*
Template Name: Slide w. shop
*/
?>
<div class="slide-header cf">
<h2><?php echo $title ?></h2>
</div>
<div class="slide-body cf">
<div class="col d-1of2 cf">
<?php echo $content ?>
</div>
<div class="col d-1of2 cf">
<?php woocommerce_content(); ?>
</div>
</div>
Documentation for woocommerce_content states:
This function is only used in the optional 'woocommerce.php' template. which people can add to their themes to add basic woocommerce support. without hooks or modifying core templates.
So in your case the solution would be to replace
<?php woocommerce_content(); ?>
with
<?php echo do_shortcode("[products]"); ?>
That should get the products to appear in your slide.
I set up WordPress with the WooCommerce Plugin and the products get looped out...all good till there.
I wanted to add the possibility that visitors are able to upvote a product. So I was looking for a plugin and found one.
But that's the actual problem! The plugin called "Like-Photo" offers me the WordPress shortcode function. If I insert the shortcode in the WordPress editor (before and after the image) all is working fine.
But I need to put that code in the PHP file (the one that loops out the products) itself.
So I tried using the PHP echo function for the shortcode as you can see below. It's not working at all. When I open up the inspector tools in my browser I only see the second shortcode part rendered out in text and it's supposed to create a div (what it does, when I paste in the shortcodes inside the WordPress post editor).
How can I fix this?
<?php echo do_shortcode('[add_voting]'); ?> <!-- shortcode beginning-->
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?> <!-- The loop for the items-->
<div class="image-box">
<div class="voteup_layer">
<div class="voteup_layer_triangle">
<div class="voteup_layer_triangle-inner"></div>
</div>
<p>CLICK 2 UPVOTE</p>
</div>
<div class="sb_title"><?php the_title(); ?></div>
<div class="arrow-up"></div>
<div id="num-id" class="count-num">20.453</div>
<a href="<?php the_permalink(); ?>">
<?php
/**
* 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' );
if ( has_post_thumbnail() ) {
//echo get_the_post_thumbnail( get_the_ID(), array(370,370) );
echo get_the_post_thumbnail( get_the_ID(), 'home-small-box' );
}
?>
</a>
</div>
<?php echo do_shortcode('[/add_voting]'); ?> <!-- shortcode end-->
I'm getting this HTML output:
<div class="home_small_box ">
<div class="image-box">
<div class="voteup_layer">
<div class="voteup_layer_triangle">
<div class="voteup_layer_triangle-inner"></div>
</div>
<p>CLICK 2 UPVOTE</p>
</div>
<div class="sb_title">FOSSIL <br> <span class="thin">Moon Explorer</span></div>
<div class="arrow-up"></div>
<div id="num-id" class="count-num">20.453</div>
<a href="http://online.com/product/fossil-moon-explorer/">
<img width="360" height="360" src="http://online.com/wp-content/uploads/2015/08/shopping-1-360x360.jpg" class="attachment-home-small-box wp-post-image" alt="shopping-1">
</a>
</div>
"[/add_voting]"
And want (this is how the HTML gets rendered once I add the shortcode inside the WordPress editor – it creates a div called "like-photo-wrapper" around the image where I placed the shortcode and adds the ability to vote):
<div class="like-photo-wrapper">
<a href="http://online.com/wp...2.jpg">
<img src="http://online.com/wp...300.jpg" alt="shopping-2" >
</a>
<div class="votes"><span class="currentVotes">Votes: 0</span>
vote on this image
</div>
</div>
The shortcode isn't working properly in my PHP code.
Check out the documentation for do_shortcode.
The gist of it is that the call to do_shortcode for a shortcode that wraps content should be like this
// In case there is opening and closing shortcode.
echo do_shortcode( '[iscorrect]' . $text_to_be_wrapped_in_shortcode . '[/iscorrect]' );
You can try something like this using output buffering to capture the output and pass it into your shortcode.
ob_start();
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?> <!-- The loop for the items-->
<div class="image-box">
<div class="voteup_layer">
<div class="voteup_layer_triangle">
<div class="voteup_layer_triangle-inner"></div>
</div>
<p>CLICK 2 UPVOTE</p>
</div>
<div class="sb_title"><?php the_title(); ?></div>
<div class="arrow-up"></div>
<div id="num-id" class="count-num">20.453</div>
<a href="<?php the_permalink(); ?>">
<?php
/**
* 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' );
if ( has_post_thumbnail() ) {
//echo get_the_post_thumbnail( get_the_ID(), array(370,370) );
echo get_the_post_thumbnail( get_the_ID(), 'home-small-box' );
}
?>
</a>
</div>
$out = ob_get_clean();
<?php echo do_shortcode('[add_voting] ' . $out . '[/add_voting]'); ?> <!-- shortcode end-->
I am trying to get the jigoshop to put everything in my main container and it appears to be not working.
My template is below:
<?php get_header(); ?>
<div id="productsidebar"><?php get_sidebar('products'); ?></div>
<div id="contentwrap">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?php endwhile; endif; ?>
</div><!-- #content -->
<?php get_footer(); ?>
And i have this in my functions file as per Jigoshops themeing (http://forum.jigoshop.com/kb/customize-jigoshop/wrap-your-themes-content-for-jigoshop)
function mytheme_open_jigoshop_content_wrappers()
{
echo '<div id="productsidebar"></div><div id="contentwrap">';
}
function mytheme_close_jigoshop_content_wrappers()
{
echo '</div>';
}
function mytheme_prepare_jigoshop_wrappers()
{
remove_action( 'jigoshop_before_main_content', 'jigoshop_output_content_wrapper', 10 );
remove_action( 'jigoshop_after_main_content', 'jigoshop_output_content_wrapper_end', 10);
add_action( 'jigoshop_before_main_content', 'mytheme_open_jigoshop_content_wrappers', 10 );
add_action( 'jigoshop_after_main_content', 'mytheme_close_jigoshop_content_wrappers', 10 );
}
add_action( 'wp_head', 'mytheme_prepare_jigoshop_wrappers' );
It was obviously erroring when i put the sidebar function in the functions file.
Can anyone advise how best to do this?
Site is http://upholstery180degree.co.uk/NewSite/
thanks
After analyzing the code your function is putting the product page in the main container as specified.
<div id="contentwrap">
<ul class="products">
<li class="product first">
Although from what it seems like you are using a different template for your shop page in which is causing it to show the widgets from you site. Your code is working properly, I would go into your product page and change the type of template it is using and have it the same as your other pages. Also you would not need the sidebar div information as it is not part of the main wrapper.
function mytheme_open_jigoshop_content_wrappers()
{
echo '<div id="contentwrap">';
}
function mytheme_close_jigoshop_content_wrappers()
{
echo '</div>';
}