woocommerce重定向到类别页面中的结帐

I can't figure out how to change the button in the category page.

I am trying to redirect to the checkout page, when that customer press the add to cart button.

With this code in the function.php I got this working for the single product page.

add_filter('woocommerce_add_to_cart_redirect', 'themeprefix_add_to_cart_redirect');
function themeprefix_add_to_cart_redirect() {
 global $woocommerce;
 $checkout_url = wc_get_checkout_url();
 return $checkout_url;
}

But this doesn't affect the category page. If the customer press the button here, nothing changes...

Hope someone has a solution for that.

you need to disable AJAX add to cart buttons on archives

go to WooCommerce->Setting->Product and then uncheck the Enable AJAX add to cart buttons on archives

enter image description here

and then your code will work on the archive pages.