Display price on add to cart button from the functions.php file in Woocommerce

前端 未结 3 1716
醉酒成梦
醉酒成梦 2020-12-19 19:08

Been trying to find something about this, but the solutions I found so far here do not work.

I need, in the single product page, to display the add to cart button li

3条回答
  •  情深已故
    2020-12-19 19:39

    Edit your woocommerce/loop/add-to-cart.php template file like this:

    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }
    
    global $product;
    
    echo apply_filters( 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
        sprintf( 'ADD TO CART - JUST %s',
            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'] ) : '',
            $product->get_price()
        ),
    $product, $args );
    

    For the single product pages do basically the same in:

    woocommerce/single-product/add-to-cart/simple.php

    And any other template you use in the add-to-cart directory.

提交回复
热议问题