Tagged: x
-
AuthorPosts
-
September 1, 2016 at 11:09 am #1157071
Hi!
On my page it looks like this before adding product:
So as you can see I already changed the text from “Add to cart” to “Lägg till”.When I add the product it looks like this:
As you can see here, it still says “Lägg till”.Then after i’ve reloaded the page it says “Redan tillagd” as I want it to say after added.
I want it to change directly and not that i need to reload it.
Here’s my code on functions.php:
add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text'); function woo_custom_cart_button_text() { foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; if( get_the_ID() == $_product->id ) { //return __('✓ Added', 'woocommerce'); return __('Redan tillagd', 'woocommerce'); } } //return __('Add to cart', 'woocommerce'); if ( has_term( 'buynow', 'product_tag', $product->ID ) ) : return __( 'Lägg till', 'woocommerce' ); else: return __( 'Lägg till', 'woocommerce' ); endif; } /** * Change the add to cart text on product archives */ add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' ); function woo_archive_custom_cart_button_text() { foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; if( get_the_ID() == $_product->id ) { //return __('✓ Added', 'woocommerce'); return __('Redan tillagd', 'woocommerce'); } } //return __('Add to cart', 'woocommerce'); if ( has_term( 'buynow', 'product_tag', $product->ID ) ) : return __( 'Lägg till', 'woocommerce' ); else: return __( 'Lägg till', 'woocommerce' ); endif; } // AJAX // ============================================================================= if ( ! function_exists( 'x_woocommerce_navbar_cart_ajax_notification' ) ) : function x_woocommerce_navbar_cart_ajax_notification() { if ( get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' ) { $notification = '<div class="x-cart-notification">' . '<div class="x-cart-notification-icon loading">' . '<i class="x-icon-cart-arrow-down" data-x-icon=""></i>' . '</div>' . '<div class="x-cart-notification-icon added">' . '<i class="x-icon-check" data-x-icon=""></i>' . '</div>' . '</div>'; } else { $notification = ''; } echo $notification; } add_action( 'x_before_site_end', 'x_woocommerce_navbar_cart_ajax_notification' ); endif;
Thank you in advance! 🙂
Hope you can help meSeptember 1, 2016 at 11:25 am #1157096Hey There,
Thanks for writing in!
The code will only work in changing the button text upon loading the page. The add to cart button text change that you wanted will require JS event triggers upon clicking on add to cart button. As this is all custom development, regretfully we won’t be able to assist further. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.
Thank you for your understanding.
-
AuthorPosts