• Resolved magicalwonders

    (@magicalwonders)


    I’ve used the following code in functions.php to remove the “Add to Cart” buttons on Shop Category pages, and replace with “Learn More” buttons that link to the product pages –

    /* REMOVE ADD TO CART BUTTON ON PRODUCT ARCHIVE (SHOP) */
    function remove_loop_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    }
    add_action('init','remove_loop_button');
    
    /* ADD NEW BUTTON THAT LINKS TO PRODUCT PAGE FOR EACH PRODUCT */
    add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');
    function replace_add_to_cart() {
    global $product;
    $link = $product->get_permalink();
    echo do_shortcode('<a href="'.$link.'" class="learnmorebutton">Learn more</a>');
    }

    This worked well and produced red buttons with white text as in this pic –
    Buttons

    My problem now is in styling these buttons. I’ve included a custom style called “learnmorebutton” in the style sheet for my child theme as follows –

    .woocommerce .learnmorebutton {
        background-color: #F7A919;
    	color: #ffffff; 
    	border-radius: 3px;
        padding: 5px 10px 5px 10px;
    	display: inline-block;
        font-family: inherit;
        font-size: 100%;
        line-height: 1;
    	text-decoration: none;

    This works for the colour, padding and radius of the button, but I don’t seem to be able to impact on the text colour. I’ve specified white, but as you can see from this page, it shows as black! https://internetsquad.co.uk/product-category/books/

    CSS is not my strong point, so I’d appreciate any guidance as to how to change the text colour for these buttons.

    Here’s a link to the custom CSS in my child theme in case there’s something else causing an issue – https://pastebin.com/BpQ7vQPv

    A lot of this CSS I did quite some time ago, so I’m not sure what the CSS starting between line 32 and line 51 is supposed to control? I’ve changed background-color: a few times, but I can’t see anything changing in my WooCommerce pages!

    Hope someone can help.

    Myles

Viewing 5 replies - 1 through 5 (of 5 total)
  • The theme style is taking precedence. Make your style more important:

    
    .woocommerce .learnmorebutton {
      color: #ffffff !important;
    }
    
    Thread Starter magicalwonders

    (@magicalwonders)

    Hey Lorro,

    Thanks for help. I had tried that earlier but I had the exclamation mark at the end of “important” and not the beginning! Lol.

    If I want to change the button colour when hovering the cursor over the button, would this be on the right lines?

    .woocommerce .a.learnmorebutton:hover {
        background-color: #E8A11E;
    • This reply was modified 7 years, 8 months ago by magicalwonders. Reason: missed a word out!
    Thread Starter magicalwonders

    (@magicalwonders)

    My last snippet to change colour of button on hover doesn’t work. Any clues as to the correct syntax?

    .woocommerce .learnmorebutton:hover {
      background-color: #E8A11E;
    }
    
    Thread Starter magicalwonders

    (@magicalwonders)

    That’s great, thank you! I appreciate the help. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘CSS issue with Add to Cart button’ is closed to new replies.