Site logo

[Resolved] icon in add to cart button

Home Forums Support [Resolved] icon in add to cart button

Home Forums Support icon in add to cart button

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #2483232
    Heinrich

    hi david,

    here is the new topic as requested. following the code from add-to-cart.php

    <?php
    /**
     * Loop Add to Cart
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/loop/add-to-cart.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see         https://docs.woocommerce.com/document/template-structure/
     * @package     WooCommerce\Templates
     * @version     3.3.0
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    global $product;
    
    echo apply_filters(
    	'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
    	sprintf(
    		'<a href="%s">%s</a>',
    		esc_url( $product->add_to_cart_url() ),
    		esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
    		esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
    		isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
    		esc_html( $product->add_to_cart_text() )
    	),
    	$product,
    	$args
    );
    #2483246
    David
    Staff
    Customer Support

    Hi there,

    on your sites Shop page, i do not see the default Woo button, it is a GB Button ?

    #2484267
    Heinrich

    hi david, i created a block hook with gb and used the “woocommerce_loop_add_to_cart_link” hook.

    but..back to roots. all i want to do is to place an svg-icon before all “add to cart” buttons.
    when i use your css solution from #1227769, may its easier to format this. can yopu have a look at the site?

    `.woocommerce ul.products li.product .button:before {
    content: ”;
    display: block;
    width: 20px;
    height: 20px;
    background-image: url(‘https://gravo.dndev.at/wp-content/uploads/images/cart.svg&#8217;);
    margin-right: 1ch;
    }

    #2484498
    David
    Staff
    Customer Support

    You have this CSS:

    .woocommerce ul.products li.product, .woocommerce ul.products li.product a {
        display: flex;
        flex-direction: column;
    }

    Which is making the button a column. Which you don’t want.
    Change it to:

    .woocommerce ul.products li.product {
        display: flex;
        flex-direction: column;
    }
    #2484609
    Heinrich

    ok, done, can you please have a look at the svg icon in the “add to cart” button. should be before the text, not above.

    tks in advance

    #2484618
    David
    Staff
    Customer Support

    Try this CSS:

    .woocommerce ul.products li.product.woocommerce-text-align-left .button {
        display: flex;
    }
    .woocommerce ul.products li.product.woocommerce-text-align-left .button:before {
        background-repeat: no-repeat;
        background-size: contain;
        background-position: 50% 50%;
        position: relative;
        top: 5px;
    }
    #2484846
    Heinrich

    hi david, the following css is working fine for all product archives.
    which chnages are necessary thats working for single product pages too?

    `.woocommerce ul.products li.product .button:before {
    content: ”;
    display: block;
    width: 20px;
    height: 20px;
    background-image: url(‘https://gravo.dndev.at/wp-content/uploads/images/cart.svg&#8217;);
    margin-right: 1ch;
    }

    .woocommerce ul.products li.product.woocommerce-text-align-left .button {
    display: flex;
    }
    .woocommerce ul.products li.product.woocommerce-text-align-left .button:before {
    background-repeat: no-repeat;
    background-size: contain;
    background-position: 50% 50%;
    position: relative;
    top: 5px;
    }

    #2485026
    Ying
    Staff
    Customer Support

    Try this:

    .woocommerce div.product form.cart .button:before {
        content:"";
        background-repeat: no-repeat;
        background-size: contain;
        background-position: 50% 50%;
        position: relative;
        top: 5px;
        background-image: url(https://gravo.dndev.at/wp-content/uploads/images/cart.svg);
        width: 20px;
        height: 20px;
        display: block;
        margin-right: 1ch;
    }
    
    .woocommerce div.product form.cart .button{
        display: flex;
    }
    
    #2485077
    Heinrich

    hello ying, perfect working, tks.

    #2485100
    Ying
    Staff
    Customer Support

    No Problem, glad to help 🙂

    #2487189
    Heinrich

    hi ying, following code is in place to hook the icon into the add to cart button in archive and mobile. its there, but not formatted correct. what i am missing? is there a way to simplify this?

    tks in advance

    `/* hooks cart svg icon in add to cart button single and archive */

    .woocommerce div.product form.cart .button:before {
    content:””;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: 50% 50%;
    position: relative;
    top: 5px;
    background-image: url(https://gravo.dndev.at/wp-content/uploads/images/cart.svg);
    width: 20px;
    height: 20px;
    display: block;
    margin-right: 1ch;
    }

    .woocommerce div.product form.cart .button{
    display: flex;
    }

    .woocommerce ul.products li.product .button:before {
    content: ”;
    display: block;
    width: 20px;
    height: 20px;
    background-image: url(https://gravo.dndev.at/wp-content/uploads/images/cart.svg);
    margin-right: 1ch;
    }

    .woocommerce ul.products li.product.woocommerce-text-align-left .button {
    display: flex;
    }
    .woocommerce ul.products li.product.woocommerce-text-align-left .button:before {
    background-repeat: no-repeat;
    background-size: contain;
    background-position: 50% 50%;
    position: relative;
    top: 5px;
    }

    #2487307
    Ying
    Staff
    Customer Support

    hi ying, following code is in place to hook the icon into the add to cart button in archive and mobile.

    I’m confused, my code is for the single product page, it’s not related to the archive.

    Do you mean the button in your archive doesn’t work well?

    If so, add this:

    .woocommerce ul.products li.product .button {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
    }

    And change this:

    woocommerce ul.products li.product .button:before {
        content: '';
        display: block;
        width: 20px;
        height: 20px;
        background-image: url(https://gravo.dndev.at/wp-content/uploads/images/cart.svg);
        margin-right: 1ch;
    }

    to

    woocommerce ul.products li.product .button:before {
        content: '';
        display: block;
        width: 20px;
        height: 20px;
        background-image: url(https://gravo.dndev.at/wp-content/uploads/images/cart.svg);
        margin-right: 1ch;
        background-repeat: no-repeat;
    }
    #2489389
    Heinrich

    hi ying, is working on single and archive now.
    tks a lot

    #2489468
    Ying
    Staff
    Customer Support

    Glad to hear that 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.