Hello as the title says.
i'm after a solution for wordpresss woocommerce with products that needs to have a added icon with a van.
same as the following link
Add an icon after product price on Woocommerce archive pages
However i've managed to made categories with fa fast-shipping and gotten the icon.
I've added the code
add_filter( 'woocommerce_get_price_html', 'prepend_append_icon_to_price', 10, 2 );
function prepend_append_icon_to_price( $price, $product ) {
if( has_term( 'fast-shipping', 'product_cat', $product->get_id() ) && ! is_product() ){
$price .= '<span style="float:right"><i class="fas fa-shipping-fast"></i></span> ';
}
return $price;
}
but it still doesn't want to pop up on my product which i dont understand.
Display Picture
I am not sure about this. Try going to the product code(where your product page with the product is shown) which will be located in themes mostly and then go below the pic and add your icon. I hope this helps :) Let me know if you find it difficult to figure it out and ill help you
Related
I want to Display Free Shipping badge underneath the ITEM TITLE (example attached) and underneath the PRICE on a single product pag.
Example
I found the below code but not sure what changes to make in order to achieve the above.
PS: it is only for items with no shipping class.
add_action( 'woocommerce_before_shop_loop_item_title', 'single_product_label', 10 );
function single_product_label() {
global $product;
if ( empty( $product->get_shipping_class() ) ) {
echo '<span class="freedel">Free UK Delivery</span>';
}
}
To achive the result as in the example picture you have to change the hook you're using.
The hook woocommerce_before_shop_loop_item_title will execute before the product title just as it states.
Instead you should use woocommerce_after_shop_loop_item which executes after the product information but before the add to cart button.
Businessbloomer.com have a wonderful visual guide to the hooks on the Woocommerce archive page that I recommend you take a look at: https://www.businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/
This is what your code should look like instead:
Obviously you will have to style it with css to get the same result as in the picture though.
add_action( 'woocommerce_after_shop_loop_item', 'archive_product_label', 10 );
function archive_product_label() {
global $product;
if ( empty( $product->get_shipping_class() ) ) {
echo '<span class="freedel">Free UK Delivery</span>';
}
}
The example picture and code you used, all look like you want this on the archive page and not on the single product page as you have written. But for good measure I'll add the link for the visual guide to the single product page and add the code for that aswell.
Single product page visual hook guide: https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/
Here are a few hooks you could use but I'm guessing the one you want is the woocommerce_before_add_to_cart_form
Here's the code for the single product page:
Notice that I changed the above function name to archive_product_label and I'm now calling this single_product_label instead. This is to avoid conflict and to make it easier to locate if you need to change the code sometime in the future.
add_action( 'woocommerce_before_add_to_cart_form', 'single_product_label', 10 );
function single_product_label() {
global $product;
if ( empty( $product->get_shipping_class() ) ) {
echo '<span class="freedel">Free UK Delivery</span>';
}
}
If you always want the same text on both archive and single product page you could also bind the two different actions to the same function
Like this:
add_action( 'woocommerce_after_shop_loop_item', 'free_shipping_product_label', 10 );
add_action( 'woocommerce_before_add_to_cart_form', 'free_shipping_product_label', 10 );
function free_shipping_product_label() {
global $product;
if ( empty( $product->get_shipping_class() ) ) {
echo '<span class="freedel">Free UK Delivery</span>';
}
}
Hope this answers your question and teaches you a little bit about how hooks, functions and actions work in wordpress/woocommerce.
Have a great day! :)
`
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_free_shipping_loop', 5 );
function bbloomer_show_free_shipping_loop() {
echo '<p class="shop-badge">Orders over $99 ship FREE</p>';
}
`
The above code is the code that displays the text under the price information on the store page.
It works fine on my site.
I want to expose this text based on product tag.
For example, you want to expose the text only for products with the "event" tag.
I hope you help
I don't know how to code. Please help me
Please try below code:
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_free_shipping_loop', 5 );
function bbloomer_show_free_shipping_loop() {
global $product;
$product_id = $product->get_id();
if ( has_term( 'event', 'product_tag', $product_id ) ) {
echo '<p class="shop-badge">Orders over $99 ship FREE</p>';
}
}
Please let me know if you find any issues
i have a wordpress site with woocommerce and flatsome theme. The theme give the possibility to add easily a custom html text before or after the add to cart button.
I would like that the html text show up only for out of stock with backorder enabled products, for single and variables products.
the theme have this code
// Add HTML after Add to Cart button
function flatsome_after_add_to_cart_html(){
echo do_shortcode(get_theme_mod('html_after_add_to_cart'));
}
add_action( 'woocommerce_single_product_summary', 'flatsome_after_add_to_cart_html', 30);
any help is appreciated
You can likely do that with just an additional couple of checks in your function. Before echoing the content - check the $product like this:
function flatsome_after_add_to_cart_html(){
global $product;
if( ! $product->is_in_stock() && $product->backorders_allowed() ){
echo do_shortcode(get_theme_mod('html_after_add_to_cart'));
}
}
add_action( 'woocommerce_single_product_summary', 'flatsome_after_add_to_cart_html', 30);
Hi there we have an online store running on WooCommerce and using the WooCommerce brands plugin (http://docs.woothemes.com/document/wc-brands/) but there is one brand that we are allowed show online with price but not allowed to actually sell.
Is there a function I can add for this particular brand to functions.php that will change the add to cart button in category or widget layout to "more info" and link to the product and then on the product page instead of the add to cart section just have a text message saying to call the store.
You can filter WooCommerce's is_purchasable method. Any item that returns false will not be able to be purchased.
function so_26378581_purchasable( $purchasable, $product ){
if ( has_term( 'your-brand', 'product_brand', $product->id ) ){
$purchasable = false;
}
return $purchasable;
}
add_action( 'woocommerce_is_purchasable', 'so_26378581_purchasable', 10, 2 );
This uses conditional logic to test whether the $product in question has the your-brand term in the product_brand taxonomy... via the has_term() function.
By the way, this is not the type of functionality that belongs in functions.php. Your theme should only be concerned with display/appearances. I would recommend that you make this its own plugin, or add to to a site specific snippets plugin.
to me it made no error message, but it did not work, as applied in my test subject and stand continues with two products of different brands.
I put this code:
function so_26378581_purchasable( $purchasable, $product ){
if ( has_term( 'product_brand', 'product_brand', $product->id ) ){
$purchasable = false;
}
return $purchasable;
}
add_action( 'woocommerce_is_purchasable', 'so_26378581_purchasable', 10, 2 );
Actually, I already got hook to customize the price in the cart page and all other page.
This is the hook to customize the product price
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
}
}
Actually, I am using woocommerce plugin. I want a hook to customize the product name displayed in the cart page and all other pages next to cart page.
I want to customize the Product name , i want to add the some static attributes to product name displayed in the cart page, order page ,order details page and all the pages next to cart page.
Thanks in advance
I wanted to share this as I managed to figure out something for my needs. (I only ever have a single item in the order as I've customised WooCommerce for holiday bookings.)
<?php
add_action( 'woocommerce_product_title', 'add_custom_name' );
function add_custom_name( $title ) {
return 'test name';
}
?>
Hopefully someone can elaborate on this further or take what has been done with the custom price code an properly re-purpose it for product names.