Summer Sale | Flat 10% OFF on All Themes Package. Use Coupon Code Summer24 | Limited Time Offer! Buy Now

WordPress Website Templates

Find Professional WordPress themes Easy and Simple to Setup

inner banner

Customize the "Add to cart" button on the page of a product with WooCommerce

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5156

    <?php
    //* NO incluyas la etiqueta de apertura

    //* Personaliza el botón “Añadir al carro” en la página de un producto con WooCommerce:
    add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’ );
    function woo_custom_cart_button_text() {

    global $woocommerce;

    foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    $_product = $values[‘data’];
    if( get_the_ID() == $_product->id ) {
    return __(‘Ya en el carrito – ¿Añadir otra vez?’, ‘woocommerce’);
    }
    }

    return __(‘Add to cart’, ‘woocommerce’);
    }

    #5160
    Grace Themes
    Member

    Hi Maria,

    Can you please write in details what problem you are getting so we can assist you?

    Regards
    Grace Themes

    #5164

    I would like to edit the php, specifically functions.php to be able to edit the button it says add to the cart. In other themes I have been able to change it from html or from function.php, but this does not work for me. Where should I edit if I want to change the text that says “add to cart”? Any advice or help is welcome. regards

    changes that I would like to add to functions.php or the site in general are as follows:

    add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’ );
    function custom_override_checkout_fields( $fields ) {
    $fields[‘order’][‘order_comments’][‘placeholder’] = ‘Plazo requerido y dirección’;
    $fields[‘order’][‘order_comments’][‘label’] = ‘Informe el plazo requerido de arriendo y la dirección donde se utilizarán los Containers’;
    return $fields;
    }
    add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’ );
    function my_custom_checkout_field( $checkout ) {
    echo ‘<div id=”my_custom_checkout_field”>’;
    woocommerce_form_field( ‘my_field_name’, array(
    ‘type’ => ‘text’,
    ‘class’ => array(‘my-field-class form-row-wide’),
    ‘label’ => __(‘Rut’),
    ‘placeholder’ => __(‘Ingrese su rut’),
    ), $checkout->get_value( ‘my_field_name’ ));
    echo ‘</div>’;
    }
    add_filter( ‘gettext’, ‘ld_custom_checkout_button_text’, 20, 3 );
    function ld_custom_checkout_button_text( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
    case ‘Finalizar compra’ :
    $translated_text = __( ‘Enviar cotización’, ‘woocommerce’ );
    break;
    }
    return $translated_text;
    }
    add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’ );
    function woo_custom_cart_button_text() {
    global $woocommerce;
    foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    $_product = $values[‘data’];
    if( get_the_ID() == $_product->id ) {
    return __(‘Solicitar Cotización’, ‘woocommerce’);
    }
    }

    return __(‘Solicitar Cotización’, ‘woocommerce’);
    }

    #5172

    listo y resuelto! al final lo resolví revisando el código del tema en functions.php pero acá debía integrarlo en el código y no al inicio. la solución completa acá : https://gist.github.com/mjesusabarca/71e3c2354152e65c4747c5eed53c51c8

    #5180
    Grace Themes
    Member

    Hi Maria

    To change ‘Add to cart’ labels in latest version WooCommerce 3.0+ you can use ‘WC Custom Add to Cart labels’ WordPress plugin. So you don’t need to add extra code in functions.php file

    https://wordpress.org/plugins/wc-custom-add-to-cart-labels/

    Regards
    Grace Themes

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