John Davidson

php - How to add an HTML code to show a logo on the product image

0 comments
Message:


I have a script from a price comparison website that I want to use on my woocommerce product page so that if my product price is cheaper on the price comparison website then a logo will appear on the product image as shown here:



The script that that I have received is like below and they told me to set this script for all product pages. The [article_number] should be replaced by woocommerce SKU. Can some one help me in adding this script in woocommerce to get the desired result? I guess I might need to call an action under functions.php of the child theme not not sure exactly which hook to call etc.


<a href="https://instore.prisjakt.nu/cheapest_redirect.php?id=[article_number]&f=123456" target="_blank"><img src="https://instore.prisjakt.nu/cheapest.php?id=[article_number]&f=123456" /></a>

I tried the below code but its not working


add_action( 'woocommerce_after_single_product_summary' , 'cheap_logo', 5 );

function cheap_logo() {
global $product;
$sku = $product->get_sku();
echo '<ahref="https://instore.prisjakt.nu/cheapest_redirect.php?id=$sku&f=123456"target="_blank"><img src="https://instore.prisjakt.nu/cheapest.php?id=$sku&f=123456" /></a>';

}


My Answer:
To add the HTML code to show a logo on the product image in WooCommerce, you can use the following code in your child theme's functions.php file:

php
add_action( 'woocommerce_before_single_product_summary' , 'add_logo_on_product_image', 5 );

function add_logo_on_product_image() {
global $product;
$sku = $product->get_sku();
echo '';
}


This code will add the logo on the product image on the single product page in WooCommerce. Make sure to replace '123456' with your actual ID and adjust the URL structure if needed. Also, ensure that the script provided by the price comparison website is correct and working as expected.

Rate this post

3 of 5 based on 8568 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us