Title: woocommerce script
Last modified: May 10, 2024

---

# woocommerce script

 *  Resolved [fabson](https://wordpress.org/support/users/fabson/)
 * (@fabson)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/woocommerce-script/)
 * After installing redirect my script for a second “buy now” button doesn’t work
   anymore
   Can anybody help?
 *     ```wp-block-code
       / Redirect to checkout upon add to cart
       add_filter( 'woocommerce_add_to_cart_redirect', 'bbloomer_redirect_checkout_add_cart' );
   
       function bbloomer_redirect_checkout_add_cart() {
          return wc_get_checkout_url();
       }
   
       // Change "Add to cart" text to "Jetzt Buchen"
       add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_button_text' );
       add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_single_add_to_cart_button_text' );
   
       function custom_add_to_cart_button_text( $text ) {
           return __( 'Jetzt Buchen', 'woocommerce' );
       }
   
       function custom_single_add_to_cart_button_text( $text ) {
           return __( 'Jetzt Buchen', 'woocommerce' );
       }
   
       // Display second "➕ Person hinzufügen" button
       add_action( 'woocommerce_after_add_to_cart_button', 'custom_display_second_add_to_cart_button' );
   
       function custom_display_second_add_to_cart_button() {
           global $product;
           ?>
           <form class="cart" action="" method="post" enctype="multipart/form-data" id="second-add-to-cart-form">
               <button type="button" class="button alt" id="second-add-to-cart-button"><?php echo esc_html( __( '+ Person hinzufügen', 'woocommerce' ) ); ?></button>
               <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>">
           </form>
           <script>
               (function($) {
                   $(document).on('click', '#second-add-to-cart-button', function(event) {
                       event.preventDefault(); // Prevent the default button click behavior
                       var button = $(this);
                       var form = button.closest('form');
                       var formData = new FormData(form[0]);
                       $.ajax({
                           type: form.attr('method'),
                           url: '<?php echo esc_url( wc_get_cart_url() ); ?>',
                           data: formData,
                           processData: false,
                           contentType: false,
                           success: function(response) {
                               // Reload the current page with anchor link #buchen
                               var url = window.location.href.split('#')[0]; // Get the current URL without the anchor
                               window.location.href = url + '#buchen'; // Add the anchor to the URL and reload
                           },
                           error: function(error) {
                               console.log('An error occurred');
                           }
                       }).done(function() {
                           location.reload();
                       });
                   });
               })(jQuery);
           </script>
           <?php
       }
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwoocommerce-script%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [John Godley](https://wordpress.org/support/users/johnny5/)
 * (@johnny5)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/woocommerce-script/#post-17747224)
 * How does this relate to Redirection? Have you created any redirects?
 *  Thread Starter [fabson](https://wordpress.org/support/users/fabson/)
 * (@fabson)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/woocommerce-script/#post-17747281)
 * indeed, I did a redirect from the cart page to the frontpage, because I didn’t
   use the cart page
 * now I deleted the cart page and wrote a script for redirecting 404s to the frontpage
   and I tested it with other redirects and the plugin and script worked, there 
   was just a conflict because I redirected this specific page
 * so my problem is solved, great plugin!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘woocommerce script’ is closed to new replies.

 * ![](https://ps.w.org/redirection/assets/icon-256x256.jpg?rev=983639)
 * [Redirection](https://wordpress.org/plugins/redirection/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/redirection/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/redirection/)
 * [Active Topics](https://wordpress.org/support/plugin/redirection/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redirection/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redirection/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [fabson](https://wordpress.org/support/users/fabson/)
 * Last activity: [2 years, 1 month ago](https://wordpress.org/support/topic/woocommerce-script/#post-17747281)
 * Status: resolved