0

Plugin is WP Configurator Pro i want that the ajax add to cart button redirect to cart page. Tried this and many other examples but did not work add_action( 'wp_footer', 'trigger_for_ajax_add_to_cart' ); function trigger_for_ajax_add_to_cart() { ?> <script type="text/javascript"> (function($){ $( ".js-wpc-submit-cart-form" ).trigger( "click" ); window.location = "cart link"; })(jQuery); </script> <?php }

Pratiksha
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 14 '23 at 13:40

1 Answers1

0

I have solved this to my own here are the steps so first I had to Disabled Ajax Call from WooCommerce

function disable_woo_cart() {   
   wp_dequeue_script( 'wc-cart-fragments');
} 
add_action( 'wp_enqueue_scripts', 'disable_woo_cart', 11 );

and after that I write this redirection code

function add_to_cart_redirect() {
    global $woocommerce;
    return $woocommerce->cart->get_cart_url();
}
add_filter( 'woocommerce_add_to_cart_redirect', 'add_to_cart_redirect' );
Pratiksha
  • 1
  • 1
  • You don't need custom code to do this. WooCommerce has this feature by default. You just need to go to WooCommerce -> Settings -> Products page and then enable the "Redirect to the cart page after successful addition" setting and disable the "Enable AJAX add to cart buttons on archives" setting – M.S Shohan Apr 17 '23 at 20:05
  • Yes, I know but that was not working so i did this with code, Thanks – Pratiksha Apr 18 '23 at 05:31