programing

Wordpress Woocommerce 제품을 카트 새로 고침 페이지에 추가하고 있습니다.

starjava 2023. 10. 4. 20:28
반응형

Wordpress Woocommerce 제품을 카트 새로 고침 페이지에 추가하고 있습니다.

저는 우커머스 사용에 문제가 있습니다.

제품을 카트에 추가하면 브라우저의 링크가 link/?add-to-cart=72가 되고, 페이지를 새로 고치면 제품이 카트에 다시 추가됩니다.

새로고침할 때마다 카트에 제품이 추가됩니다.저는 우커머스를 제외한 모든 플러그인을 비활성화했지만 여전히 동일합니다.

이 문제를 해결할 방법이 있습니까?감사해요.

한 번은 같은 문제가 있었는데, 여기 테마에 추가해야 할 코드가 있습니다.functions.php파일 또는 사용자 지정 플러그인:

add_action('add_to_cart_redirect', 'cipher_add_to_cart_redirect');
 
function cipher_add_to_cart_redirect($url = false) {
 
     // If another plugin beats us to the punch, let them have their way with the URL
     if(!empty($url)) { return $url; }
 
     // Redirect back to the original page, without the 'add-to-cart' parameter.
     // We add the `get_bloginfo` part so it saves a redirect on https:// sites.
     return get_bloginfo('wpurl').add_query_arg(array(), remove_query_arg('add-to-cart'));
 
}

사용자가 카트에 제품을 추가하면 리디렉션이 추가됩니다.도움이 되었으면 좋겠습니다.

답변 감사합니다 @asfandyar-khan, 저는 잘 맞습니다.

약간의 업데이트만 해도 add_to_cart_redirect는 버전 3.0.0 이후로 더 이상 사용되지 않습니다. 대신 wocommerce_add_to_cart_redirect를 사용해야 합니다.

다음과 같은 이점이 있습니다.

add_action('woocommerce_add_to_cart_redirect', 'example_add_to_cart_redirect');

function example_add_to_cart_redirect($url = false) {
 
     // If another plugin beats us to the punch, let them have their way with the URL
     if(!empty($url)) { return $url; }
 
     // Redirect back to the original page, without the 'add-to-cart' parameter.
     // We add the `get_bloginfo` part so it saves a redirect on https:// sites.
     return get_bloginfo('wpurl').add_query_arg(array(), remove_query_arg('add-to-cart'));
 
}

언급URL : https://stackoverflow.com/questions/46882463/wordpress-woocommerce-product-is-being-added-to-cart-on-page-refresh

반응형