Customize the "Add to cart" button on the page of a product with WooCommerce
Tagged: add to cart, button, cart, customize, woocommerce
- This topic has 4 replies, 2 voices, and was last updated 7 years, 3 months ago by Grace Themes.
-
AuthorPosts
-
July 25, 2017 at 11:18 pm #5156Maria Jesus Abarca CruzParticipant
<?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’);
}July 26, 2017 at 6:50 am #5160Grace ThemesMemberHi Maria,
Can you please write in details what problem you are getting so we can assist you?
Regards
Grace ThemesJuly 26, 2017 at 2:29 pm #5164Maria Jesus Abarca CruzParticipantI 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’);
}July 27, 2017 at 12:25 am #5172Maria Jesus Abarca CruzParticipantlisto 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
July 28, 2017 at 7:39 am #5180Grace ThemesMemberHi 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 -
AuthorPosts
- You must be logged in to reply to this topic.