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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #46905

    manciaz
    Participant

    Hi 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!
    G

    #46950

    Artem Temos
    Keymaster

    Hello,

    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

    #46993

    manciaz
    Participant

    Great 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 🙁
    Thanks

    #47001

    manciaz
    Participant

    PS: 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>';

    #47007

    Artem Temos
    Keymaster

    Sorry, but the icon can’t be changed. It is possible with additional CSS code customization only.

Viewing 5 posts - 1 through 5 (of 5 total)