I want to display a wordpress shortcode after the product title on my woocommerce products page.
Does anyone know how I can do this? I have looked all over but I cannot work out where or how to input this. All I keep doing is breaking the site :(
You can use woocommerce_template_single_title hook. Example is given below.
add_action('woocommerce_template_single_title', 'your_function');
function your_function(){
// Do your stuff
}
Woo Commerce doesn't have a shortcode for displaying a product name but you can easily create your own function.
function displayProductName($item)
{
$productName = get_the_title($item['id']);
return $productName;
}
add_shortcode('product_name', 'displayProductName');
Add the above code to your functions.php file and then use [product_name id="10"] to output the product title, where id is the id of the product in question. The above example uses the get_the_title() in-built WordPress function:
https://developer.wordpress.org/reference/functions/get_the_title/
Related
I have a Woocommerce store that is using Elementor mini cart.
I would like to add suggested products inside the mini cart, using this php code:
function content_below_products_minicart() {
echo 'You may also like these products';
echo do_shortcode('[products ids="13"]');
};
add_action( 'woocommerce_mini_cart_contents', 'content_below_products_minicart', 10);
And it works fine, but unfortunately the UI is not the best.
So I would like to customize the CSS but the styles of those products are the same as the product archive, so editing that CSS code will also modify the appearance of the products in the Archive.
How can I create an HTML Class that I can edit on its own?
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.
<img src="https://instore.prisjakt.nu/cheapest.php?id=[article_number]&f=123456" />
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 '<img src="https://instore.prisjakt.nu/cheapest.php?id=$sku&f=123456" />';
}
I'm trying to learn WordPress and developing custom plugins. I'm trying to make a custom plugin where it will display just the Product Image from the Woocommerce plugin to the page. I have 1 product, and I've been reading documentation and haven't really found anything that explains it clearly or works. This is all I have now
<?php
$gallery_shortcode = '[gallery id="' .intval($post->$post_parent).'"]';
print apply_filters('the_content', $gallery_shortcode);
?>
Honestly the question is not very clear, so I'll try to guess what you're looking for.
You can "get" a product image with this function:
woocommerce_get_product_thumbnail();
If you need it in a custom single product PHP template, simply:
echo woocommerce_get_product_thumbnail();
If you need it in a shortcode inside the single product page:
add_shortcode( 'product_image', 'bbloomer_product_image_shortcode' );
function bbloomer_product_reviews_shortcode() {
return woocommerce_get_product_thumbnail();
}
...and then use [product_image] shortcode to show the image
Tl;dr: I want to use similar functionality in WC shortcodes but within the WC shop page.
I have many custom Woocommerce shortcodes I have created. I use them throughout non-shop pages.
E.g:
function displayProductIngredients($item) {
$product = wc_get_product($item['id']);
return $product->get_attribute( 'ingredients' );
}
add_shortcode('product_ingredients', 'displayProductIngredients');
I would like to use them in the archive-product.php page too.
E.g. in the example this shortcode adds the content of the "ingredients" attribute. How can the same be added for each new product added?
Is this just a case of moving around some of the php? If so, how might it look?
Thank you very much.
i have tried many way but can not figure out. I want to hide basic price (top price) of product details page and want to replace with bottom price (total price). Something like THIS. Could anyone tell me how i do that? is there any hook in woocommerce for do this?
I have tried with this hook:
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price',10);
But it does't work. Thanks me advance.
Two big points here.
Your code is referencing the shop loop, while your screen shot is the single product page. Since your code is targeting the wrong page, you aren't likely to see any change.
remove_action() always needs to be called from inside a function and not directly from your theme's functions.php. See the codex.
So, taking those points into consideration, something like the following ought to remove the price from the single product page.
function so_46304892_remove_price() {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
}
add_action( 'woocommerce_before_single_product', 'so_46304892_remove_price' );
You can use this hook woocommerce_get_price_html and check whether it is a single product page or not
For eg.
add_filter('woocommerce_get_price_html','your_func_name',10,2);
function your_func_name($price, $product_data) {
if(is_product()) {
$price = '';
}
return $price;
}