Wordpress Woocommerce: Single product page gallery of variations - wordpress

The thing I need is variation to be changed on selected products when I click on image associated with it. The same way as displayed image changes clicking variation from dropdown (but vice versa). I spent days looking for solution, that must be so simple. Is it solvable with writing some code? I don’t want plugins like swatches. I am not born English speaker, so hope it’s understandable enough. Thanks for ANY kind of help.
Here:
http://obrazyzedreva.cekuj.net/produkt/svata-rodina/
Wordpress, Woocommerce, Customify template

This is how I solved it:
part of product-image.php
<div>
<div>
<?php
if( $product->is_type( 'variable' ) ){
?>
<div>
<div>
<strong>Vyberte si variantu:</strong>
</div>
<?php
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
echo '<div style="display:inline-block">';
echo '<img class="selector_'. $variation['variation_id'] .'" width="80" height="80" src=' . $variation['image']['url'] . ' style="margin-right:7px;">';
echo '</div>';
}
?>
</div>
<script type="text/javascript">
jQuery(function($){
<?php foreach ( $variations as $variation ) {
foreach($variation['attributes'] as $attributes) {
?>
$('.selector_<?php echo $variation['variation_id'] ?>').click(function(){
$('select[name="attribute_model-vyrobni-cislo"] option[value="<?php echo $attributes ?>"]').attr("selected","selected").trigger('change');
});
<?php
}
}
?>
});
</script>
<?php
}
?>
</div>
</div>

Related

Relevanssi - Duplicate Searches logged

I'm using (and loving) Relevanssi plugin for WordPress. Having a problem though with searches being logged twice in user searches.
Found this comment in the plugin comments about it being a problem with the template.
When digging around my search template, I just removed everything, then added things piecemeal until I had double results again.
This is the line in my search template that seems to be the trouble maker, but I don't necessarily see why.
<div style="background-image: url();"></div>
It makes 0 sense to me. If that bit of STATIC html is in the content-search.php template, I get double searches logged. If I remove it, or if all of the articles have get_the_post_thumbnail_urls, then I only get one search logged.
It seems to have something to do with style="background-image:url();" not having a value?
Here's the bigger picture:
search.php:
<?php
global $wp_query;
if ( $wp_query->found_posts > 12 ) {
$search_count = '1 - ' . $wp_query->post_count . ' of ' . $wp_query->found_posts;
} else {
$search_count = $wp_query->post_count;
}
?>
<div class="search-pg-header">
<?php include get_template_directory() . '/templates/partials/search-form.php'; ?>
<?php if ( get_search_query() !== '' ) { ?>
<h1>Showing <?php echo $search_count; ?> results for <?php echo get_search_query() ?></h1>
<?php } // end if ?>
</div>
<div class="posts-container">
<?php if ( have_posts() ):
while ( have_posts() ) : the_post();
get_template_part( 'templates/content', 'search' );
endwhile;
else: ?>
<p>There are no articles that matched your search.</p>
<?php endif; ?>
</div>
<?php if ( $wp_query->max_num_pages > 1 ) { ?>
<button>Show More</button>
<?php } // end if ?>
content-search.php:
<article data-link="<?php the_permalink(); ?>">
<div style="background-image: url(<?php the_post_thumbnail_url('card-white');?>);"></div>
<div>
<h2><?php the_title(); ?></h2>
<?php if (get_post_type() === 'post') { get_template_part('templates/entry-meta'); } ?>
<?php if ( has_excerpt() ) {?>
<p><?php echo get_the_excerpt(); ?></p>
<?php } //end if ?>
</div>
</article>
I did a fresh install of Wordpress and tested out this bizarre theory with 2017 theme. True enough, if I add <div style="background-image:url();"></div> to the template template-parts/post/content-excerpt.php then duplicate searches are logged.
If that div has an image: <div style="background-image:url(http://image.com);"></div> only one search is logged.
As Mikko Saari (Relevanssi) so kindly helped me with, this is actually unintended behavior from the browser.
It's definitely nice to at least have an explanation for this.
I was able to prevent this by just putting a check to see if there was a bkgd image before I rendered the inline style to the page, and now I know to be much more careful with this kind of thing in the future!
$style = ! empty( get_the_post_thumbnail_url($the_post, 'card-white') ) ?
'style="background-image: url(' . get_the_post_thumbnail_url($the_post, 'card-white') . ');"' : '';
<div class="article-card__img" <?php echo $style; ?>></div>

Rendering an image on a WooCommerce product page

Using the Advanced Custom Fields plugin, I am trying to render an image on a single product page in WooCommerce.
I found this snippet of code from someone who is doing the same thing, but is rendering a text field instead. How would I change this to render an image?
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_top_category_desc', 1 );
function woocommerce_template_top_category_desc (){
$terms = get_the_terms( $post->ID, 'wc-attibute-class' );
if ( !empty($terms)) {
$term = array_pop($terms);
$text= get_field('txt-field', $term);
if (!empty($text)) {
echo $text;
}
}
}
So far I have this, but it's not working. The add action is correct because I was using it for something else, but starting at $terms is where I get lost and is obviously not right.
add_action( 'woocommerce_product_thumbnails' , 'add_below_featured_image', 9 );
function add_below_featured_image() {
$terms = get_the_terms( $post->ID, '496' );
if ( !empty($terms)) {
$term = array_pop($terms);
$image = get_field('banner_feedback', $term);
if (!empty($image)) {
echo $image;
}
}
}
Figured it out.
add_action( 'woocommerce_product_thumbnails' , 'add_below_featured_image', 9 );
function add_below_featured_image() {
if( is_single( pageidhere ) ) {
echo '<br><img src="urlhere">';
}
}
Steps to add custom gallery below featured image in woocommerce single product page(you can modify suitably to add just a single image):
Create an ACF for Image Gallery.
Copy the template for product-image.php from /plugins/woocommerce/templates/single-product to themes/your-child-theme/woocommerce/single-product/
Add the following code to product-image.php just before the closing div of
"images"
Add the images you want in the gallery to your single product admin page in the ACF custom field.
`
<?php $images = get_field('product_image_gallery'); ?>
<div class="mycustom_image_gallery">
<?php if($images): ?>
<div class="popup-gallery">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>"
class="lightbox-link"
title="<?php echo $image['caption']; ?>"
data-description="<?php echo $image['description']; ?>">
<div class="image-wrap">
<img src="<?php echo $image['sizes']['thumbnail']; ?>">
</div>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
`

Wordpress is_page_template query

i use a Plug-in on my wordpress site which uses a query to show search results, thats the code of the query:
if ( $query->have_posts() )
{
?>
<?php echo $query->found_posts; ?> Ergebnisse gefunden<br />
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div>
<?php if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small"); echo '</p>'; } ?>
<h2><?php the_title(); ?></h2>
</div>
<?php
}
?>
Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
Previous | Next
<?php
}
else
{
echo "No Results Found";
}
The search should only display results from pages who uses a specific page template (mytemplate.php)
I found the Docs http://codex.wordpress.org/Function_Reference/is_page_template who explain this, but i dont get it to work inside the above query.
any help would be nice :) thx
Please do as below.
if ( is_page_template( '{enter the name of page template with extension}' ) ) {
// Enter your if code here
} else {
// Enter your else code here.
}
For this code to work you must select the page template option while creating the page in WordPress Admin Interface.

Woocommerce with wordpress - how can I display category image?

Have got this working on general wordpress categories using this plugin:
https://wordpress.org/plugins/categories-images/
Then adding the following to the category.php template as advised on another thread.
<?php if (function_exists('z_taxonomy_image_url')) { ?>
<img src="<?php echo z_taxonomy_image_url(); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
I'd like to do exactly the same with the product categories. Actually ideally I'd like to be able to add background images to each category so that the description text can go over the top, like the way this shop works:
http://www.natures-own.co.uk/Antioxidants/
Is this possible with some minor code tweaking, or better still is there a woocommerce equivalent to the wordpress plugin I've used?
I cannot find any resources for this anywhere, everything I find on searching is referring to just thumbnail of a category list as far as I can see!
Thanks in advance
Pat
You can add the category image and description by adding the following to the archive-product.php file after <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?> that if statement:
if (is_product_category())
{
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
//if you only want the image, uncomment the two lines below
//list($width, $height) = getimagesize($image);
//echo '<img src="'.$image.'" alt="" width="'.$width.'" height="'.$height.'"/>';
$cat_id=$cat->term_id;
$prod_term=get_term($cat_id,'product_cat');
$description=$prod_term->description;
echo '<div class="category-description" style="background-image:url('.$image.');">'.$description.'</div>';
}
To display Woocommerce Category image
use this code -
add_action('woocommerce_archive_description', 'woocommerce_add_category_image', 20);
function woocommerce_add_category_image()
{
global $product;
if (is_product_category())
{
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($thumbnail_id);
if ($image)
{
echo '<img src="' . esc_url($image) . '" alt="" />';
}
}
}

Notice: Undefined index: type // Wordpress Theme

I have spent several hours with my wordpress Theme. It is not compatible with WP version 3.4/ 3.51. When DEBUG is set to TRUE / available:
Many Notifications appear. As for now I have completed all notifications, only one is left. I can´t find any solutions. I hope someone can help me.
I have only basic knowleadge in PHP.
Notice: Undefined index: type in
<?php foreach ($options as $value) {
switch ( $value['type'] ){
case "section": $i++; ?>
This is what notification is for: switch ( $value['type'] ){
Here is part of page. Itś a Theme Option page for my Theme.
<form method="post" enctype="multipart/form-data" >
<div class="info top-info">
<div class="settingsaved">
<?php
// Form results if ( isset( $_REQUEST['saved'] ) ) echo '<div id="message" class="updated2 fade"><p><strong>Settings Saved</strong></p></div>';
if ( isset( $_REQUEST['reset'] ) ) echo '<div id="message" class="updated2 fade"><p><strong>Settings Reset</strong></p></div>';
?></div>
<div style="float: right;"><input type="submit" name="save" class="button-primary save-options" value="Save Changes"></div><div style="clear: both;"></div></div><div id="content" class="clearfix"><div id="options_tabs" class="ui-tabs">
<ul class="options_tabs ui-tabs-nav">
<?php foreach ($options as $value) {
switch ( $value['type'] ){case "section": $i++;
?><li class="ui-state-default ui-corner-top">
<a href="#option_<?php echo $value['id']; ?>">
<?php if ($value['icon']){ ?>
<img src="<?php echo $theme_directory ?>mm/files/images/icons/<?php echo $value['icon'] ?>"/>
<?php } ?>
div style=" display: inline-block; margin-left: 6px; margin-top: -1px;position: absolute;"><?php echo $value['name']; ?></div><span></span></a></li>
<?php break;
}}?>
</ul><?php foreach ($options as $value) {
switch ( $value['type'] ) {
// --> open the option section
case "open": ?><?php break;// --> create a subheadline
case "subhead": ?>
<div class="mmtheme-sub-header"> <h2> <?php echo $value['name']; ?>
<div style="float: right;">Description<div class="description"><div class="inner"><?php echo htmlspecialchars_decode( $value['desc'] ); ?></div></div></div> </h2></div>
<?php break;
// --> close the option section
case "subhead2": ?>
Here is code for mm.php
LINK TO FULL PHP FILE ( mm-includes.php )
Looking forward to get a solution, Thanks in advance!
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Thanks to tJerry! You solved my problems!
I have one notice left, appear now - below is notice and suorce. Nice if I get it off my eye, anyone?
This is Notice in Theme option.
Notice: Use of undefined constant update_notifier - assumed 'update_notifier' in \wp-content \themes\bardot\includes\update_notifier.php on line 17
*line 17 *
add_dashboard_page( $theme_data['Name'] . 'Theme Updates ', ' <span class="update-plugins
count-2"><span class="update-count">New Theme Update</span></span>', 'administrator','m3-
updates', update_notifier);
If you insert this before the switch statement, your notice will disappear, as the switch block will be skipped if the value isn't set.
if(!isset($value['type']))
continue;

Resources