Search code examples
csswordpressbuttonwoocommercecart

I want to add my custom add to cart button


I'm using motta theme for WooCommerce, and i don't like their add to cart button, it's too big, i want it to be so simple like a plus button, can you guys help me?

I tried to add many suggested codes in my functions.php file but they didn't work.


Solution

  • You can add custom PHP code to your child theme’s functions.php file

        // Add custom Add to Cart button
    add_filter('woocommerce_loop_add_to_cart_link', 'custom_add_to_cart_button', 10, 2);
    function custom_add_to_cart_button($button, $product) {
        if ( $product->is_type( 'simple' ) ) {
            $url = $product->add_to_cart_url();
            $label = $product->add_to_cart_text();
            $button = '<a href="' . esc_url( $url ) . '" data-quantity="1" class="button custom-add-to-cart-button" data-product_id="' . $product->get_id() . '" aria-label="' . $label . '" rel="nofollow">' . $label . '</a>';
        }
        return $button;
    }