Home › Forums › WoodMart support forum › "woocommerce_loop_add_to_cart_link" replacement and "woodmart-add-btn" class
"woocommerce_loop_add_to_cart_link" replacement and "woodmart-add-btn" class
- This topic has 4 replies, 2 voices, and was last updated 6 years, 9 months ago by Artem Temos.
-
AuthorPosts
-
March 19, 2018 at 1:18 am #46905
manciazParticipantHi there!
I have an issue with button texts replacement via functions.php.I added this snippet in my child theme functions, in order to change button url and text in a particular condition (vendor didn’t set a paypal address).
Here is the code:add_filter( 'woocommerce_loop_add_to_cart_link', 'conditionally_replacing_add_to_cart_button', 10, 2 ); function conditionally_replacing_add_to_cart_button( $button, $product ) { $product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id; $vendor_id = WCV_Vendors::get_vendor_from_product( $product_id ); $value = get_user_meta( WCV_Vendors::get_vendor_id( $vendor_id ), 'pv_paypal', true ); if ( empty( $value ) ){ $button_text = 'mynewbuttontext'; $button = '<a class="" href="' . $product->get_permalink() . '">' . $button_text . '</a>'; } return $button; }
The problem is that that change seems to make the button not to respect class “woodmart-add-btn” anymore, as you can see here: https://www.booksbud.it/categoria-prodotto/scuole-medie/
You can see the difference between the “add to cart” button of first item (that is a “core” button) and the second one (created by the snippet): my new button button has different padding (is smaller) and the text is not replaced by the cart symbol but is always visible. Is there any way to make that button work like the first one?
Thank you!
GMarch 19, 2018 at 7:30 am #46950
Artem TemosKeymasterHello,
Try to change your code and replace this line
$button = '<a class="" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
with this one
$button = '<a class="" href="' . $product->get_permalink() . '"><span>' . $button_text . '</span></a>';
Regards
March 19, 2018 at 9:14 am #46993
manciazParticipantGreat man! It works… problem solved.
Last questions. Is there any way to change the cart icon too (from that code in functions)?
It could be useful the icon to be something like an information icon, not a cart.And what about if a product goes out of stock? Have you got a code to change the icon in that case too? I believe the cart for a non purchasable product is not the best…
Many questions 🙁
ThanksMarch 19, 2018 at 9:27 am #47001
manciazParticipantPS: to make it works in quick view mode I needed to add “button product_type_simple add_to_cart_button ajax_add_to_cart add-to-cart-loop” class to the button there
$button = '<a class="" href="' . $product->get_permalink() . '"><span>' . $button_text . '</span></a>';
March 19, 2018 at 9:56 am #47007
Artem TemosKeymasterSorry, but the icon can’t be changed. It is possible with additional CSS code customization only.
-
AuthorPosts
- You must be logged in to create new topics. Login / Register