Link Woocommerce custom placeholder image to product page - wordpress

On my woocommerce e-commerce page https://www.vattenliv.se/produkt-kategori/filter/ozon-och-proteinskimmer/ there are some products that does not have any product image set. Instead the custom placeholder image shows. Is there a way to make these placeholder images link to each product page, just like the other products?
The site uses the theme OceanpWP and Elementor page builder.
Peter

I believe the best way to do this is by using a child theme, to ovewrite the woocommerce function. This code in your child theme functions.php file should work.
<?php
if (!function_exists('woocommerce_get_product_thumbnail')) {
function woocommerce_get_product_thumbnail($size = 'shop_catalog', $deprecated1 = 0, $deprecated2 = 0) {
global $post;
if (has_post_thumbnail()) {
return ''.get_the_post_thumbnail($post->ID, $size).'';
}
elseif(wc_placeholder_img_src()) {
return ''.wc_placeholder_img( $size ).'';
}
}
}
?>

Related

Woocommerce Product Page Breadcrumb-title edit

i want it to be
I want to replace the top Store page name on the wordpress product page with the product name, can anyone help?
example:
i want it to be
How can I do? There is no such setting in the properties of the theme?
Not knowing what theme you are using or how the Shop title is being generated, try adding this code to your functions.php file
add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function woo_shop_page_title( $page_title ) {
if( 'Shop' == $page_title) {
return the_title();
}
}
This code replaces the page title Shop with the title of the product (post).

Add button on Homepage - WordPress Custom Theme

I have a website with WordPress custom theme.
Is there any guide how to add a custom button/image on the left side of homepage?
Something eye-catching.
Try below code
add_action('wp_footer','placingButton');
function placingButton()
{
if ( is_front_page() ) {
echo '<div class="button">Your button</div>';
}
}

Targeting the shop page only

This is what I need to do:
To target only the main shop page with CSS (a specific custom class I created as mentioned below).
This is what I've done and tried so far:
I have an override template of archive-product.php in my child theme.
In this override template I've added a div with a custom class custom-shop-class just before the product loop start, because I want to target the looped products specifically.
I tried targeting with class page-id-4 because if I hover over the "shop" page in wp-admin, it gave me http://.../post.php?post=4&action=edit
The problem I'm having is as follows:
From what I've discovered is that the same archive-product.php template is being used in the other various shop pages and not only in the main "shop" page (correct me if I'm wrong), so when I target my custom-shop-class with CSS, it affects all the other shop pages using the same template file, and it must not.
There is no unique identifier or class specifically for the shop page, something like the page-id-?? class in the body tag (as in the usual WP pages).
Any suggestions on the best method/solution?
Set a conditional statement to check for the primary shop page, then echo the div in question if that statement evaluates to true.
WooCommerce Conditional Tag for main shop page:
is_shop()
Example
if (is_shop()) {
echo "<div class='custom-shop-class'></div>";
} else {
echo "<div class='custom-product-category-class'></div>";
}
Alternatively:
<?php if (is_shop()):?>
<div class="custom-shop-class"></div>
<?php else: ?>
<div class="custom-product-category-class"></div>
<?php endif;?>
Conditional Tags | WooThemes Documentation
Using the filter body_class with the is_shop conditional you can target the main WooCommerce shop page.
add_filter( 'body_class', 'woo_shop_class' );
// Add WooCommerce Shop Page CSS Class
function woo_shop_class( $classes ) {
if ( is_shop() ) // Set conditional
$classes[] = 'woo-shop'; // Add Class
return $classes;
}
The code goes in your themes functions.php file.
To build on the answer provided here, how might I go further and add a unique identifier to the shop page based on the active WPML language? (I'm basically trying to reduce a font size on the German version of the shop page only - it's proving surprisingly difficult to do)

How do I change the title of a Wordpress page within the template?

I am setting up a wordpress theme and it has the "logo" h1 tag at the top which shows the title of the site. On the blog page specifically though I'd like to change the title in the H1 tag.
I am aware there may be some php that does something like this: if blog page show this h1 tag (code) and for every other page show this h1 tag (code).
Is this possible?
Thanks kindly
Please use the below code instead of code which is now using to display the page title.
<?php
if ( is_page( '{enter your blog page slug here}' ) ) {
echo '<h1>{enter your blog page title here}</h1>';
} else {
echo '<h1>{enter your non-blog page title here}</h1>';
}
?>
You can query your current page template with meta.
You can get current page template this meta tag:
_wp_page_template
And full code:
if( get_post_meta($post->ID, '_wp_page_template', true) == "your-template.php" ){
// current page is created with your template
} else{
// other page template or defult template
}
Assuming you have separate template for your blog page, like blog.php in your theme directory.
Then you should follow below code:
if ( is_page_template( 'blog.php' ) ) {
// Current Template is Blog
} else {
// Other Pages
}
More info: http://codex.wordpress.org/Function_Reference/is_page_template
Update:
If blog the one of your page in WordPress then follow below code:
if(is_page('id or slug of WP Blog Page')) {
// This is blog page
} else {
// This is other page
}
If that does not work then you should try including different header files using get_header function.
More Info: http://codex.wordpress.org/Function_Reference/get_header
Suggestion: I would suggest to create new page template for your blog page and then you are good to go. You can refer this to create new page template and assign to page.

How to hide classes on some pages in WordPress?

How do I hide some CSS classes on some pages in WordPress? Like if I want to hide featured image in blog posts we use:
.single .post-thumbnail {
display:none;
}
I want the class (like .single) for homepage, search page, archives, etc.
You would need to target the page class. If you look at the source code on whatever page you are on, you'll notice the body class include a unique identifier for your page. You can then target that way. See the Codex for a full run-down of page classes.
Home is home, search is search, archives is archive. The homepage won't be single because that's reserved for posts.
You could set custom ones with a filter.
add_filter( 'body_class', 'new_body_class' );
function new_body_class( $classes ) {
if ( is_front_page())
$classes[] = 'custom-class';
return $classes;

Resources