skip to Main Content

Hello im trying to overwrite woocommerce_loop_add_to_cart_link function but is not working, i already created the “woocommerce” folder in my theme, than add the “templates” and inside the folder “loop” where have the file that i need to edit that is “add-to-cart.php”.

But after changin my href button add, is not taking effect, here is the code:

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

global $product;

echo apply_filters( 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
    sprintf( '<a href="%s" data-quantity="%s" class="%s btn btn-warning btn-block btn-sm btn-add-cart" %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 );

2

Answers


  1. To override woocommerce template files in your theme , correct path will be

    yourtheme/woocommerce/loop/add-to-cart.php

    instead of

    yourtheme/woocommerce/templates/loop/add-to-cart.php

    This will fix your problem.

    Login or Signup to reply.
  2. If you just want to change the text there’s a plugin recommended by WooCommerce – https://wordpress.org/plugins/wc-custom-add-to-cart-labels/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search