Change remove cart item url in Woocommerce
My simple question is that how I can make this code working
esc_url( WC()->cart->get_cart_url->get_remove_url( $cart_item_key ) ),
the above i have tried and the current code is below
esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ),
so instead my current url : example.com/?removed_item=1
should be something like example.com/cart/?removed_item=1
Thanks for suggestion
php wordpress url woocommerce cart
add a comment |
My simple question is that how I can make this code working
esc_url( WC()->cart->get_cart_url->get_remove_url( $cart_item_key ) ),
the above i have tried and the current code is below
esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ),
so instead my current url : example.com/?removed_item=1
should be something like example.com/cart/?removed_item=1
Thanks for suggestion
php wordpress url woocommerce cart
add a comment |
My simple question is that how I can make this code working
esc_url( WC()->cart->get_cart_url->get_remove_url( $cart_item_key ) ),
the above i have tried and the current code is below
esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ),
so instead my current url : example.com/?removed_item=1
should be something like example.com/cart/?removed_item=1
Thanks for suggestion
php wordpress url woocommerce cart
My simple question is that how I can make this code working
esc_url( WC()->cart->get_cart_url->get_remove_url( $cart_item_key ) ),
the above i have tried and the current code is below
esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ),
so instead my current url : example.com/?removed_item=1
should be something like example.com/cart/?removed_item=1
Thanks for suggestion
php wordpress url woocommerce cart
php wordpress url woocommerce cart
edited Nov 23 '18 at 19:40
LoicTheAztec
85.2k136095
85.2k136095
asked Nov 23 '18 at 18:50
R.K.BhardwajR.K.Bhardwaj
1,6071615
1,6071615
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
WC_Cartget_remove_url()method is deprecated and replaced bywc_get_cart_remove_url()function.
It can be used as follow:
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Get the remove Url for the current cart item
$remove_url = wc_get_cart_remove_url( $cart_item_key );
}
this will give you an url like: https://www.example.com/cart/?removed_item=1…
Now to make changes on this Url, you can use woocommerce_get_remove_url dedicated filter hook, like in this example:
add_filter( 'woocommerce_get_remove_url', 'custom_item_remove_url', 10, 1 );
function custom_item_remove_url( $remove_url ) {
$cart_page_url = wc_get_page_permalink( 'cart' );
$replacement_url = wc_get_page_permalink( 'shop' ); // Shop page
// Change URL to shop page + remove Url query vars
$remove_url = str_replace($cart_page_url, $replacement_url, $remove_url);
return $remove_url;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
this will give you an url like: https://www.example.com/shop/?removed_item=1…
instead shop i want to redirect to cart and i have change into your code its not working
– R.K.Bhardwaj
Nov 24 '18 at 6:50
on my mini cart when i remove the cart item its not redirecting to view cart page this is the problem with your code the URL showing bottom but its not redirecting to view cart page
– R.K.Bhardwaj
Nov 24 '18 at 8:15
@R.K.Bhardwaj It's not possible to do it for minicart as there is no redirection and it's managed by ajax.
– LoicTheAztec
Nov 24 '18 at 10:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451684%2fchange-remove-cart-item-url-in-woocommerce%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
WC_Cartget_remove_url()method is deprecated and replaced bywc_get_cart_remove_url()function.
It can be used as follow:
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Get the remove Url for the current cart item
$remove_url = wc_get_cart_remove_url( $cart_item_key );
}
this will give you an url like: https://www.example.com/cart/?removed_item=1…
Now to make changes on this Url, you can use woocommerce_get_remove_url dedicated filter hook, like in this example:
add_filter( 'woocommerce_get_remove_url', 'custom_item_remove_url', 10, 1 );
function custom_item_remove_url( $remove_url ) {
$cart_page_url = wc_get_page_permalink( 'cart' );
$replacement_url = wc_get_page_permalink( 'shop' ); // Shop page
// Change URL to shop page + remove Url query vars
$remove_url = str_replace($cart_page_url, $replacement_url, $remove_url);
return $remove_url;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
this will give you an url like: https://www.example.com/shop/?removed_item=1…
instead shop i want to redirect to cart and i have change into your code its not working
– R.K.Bhardwaj
Nov 24 '18 at 6:50
on my mini cart when i remove the cart item its not redirecting to view cart page this is the problem with your code the URL showing bottom but its not redirecting to view cart page
– R.K.Bhardwaj
Nov 24 '18 at 8:15
@R.K.Bhardwaj It's not possible to do it for minicart as there is no redirection and it's managed by ajax.
– LoicTheAztec
Nov 24 '18 at 10:31
add a comment |
WC_Cartget_remove_url()method is deprecated and replaced bywc_get_cart_remove_url()function.
It can be used as follow:
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Get the remove Url for the current cart item
$remove_url = wc_get_cart_remove_url( $cart_item_key );
}
this will give you an url like: https://www.example.com/cart/?removed_item=1…
Now to make changes on this Url, you can use woocommerce_get_remove_url dedicated filter hook, like in this example:
add_filter( 'woocommerce_get_remove_url', 'custom_item_remove_url', 10, 1 );
function custom_item_remove_url( $remove_url ) {
$cart_page_url = wc_get_page_permalink( 'cart' );
$replacement_url = wc_get_page_permalink( 'shop' ); // Shop page
// Change URL to shop page + remove Url query vars
$remove_url = str_replace($cart_page_url, $replacement_url, $remove_url);
return $remove_url;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
this will give you an url like: https://www.example.com/shop/?removed_item=1…
instead shop i want to redirect to cart and i have change into your code its not working
– R.K.Bhardwaj
Nov 24 '18 at 6:50
on my mini cart when i remove the cart item its not redirecting to view cart page this is the problem with your code the URL showing bottom but its not redirecting to view cart page
– R.K.Bhardwaj
Nov 24 '18 at 8:15
@R.K.Bhardwaj It's not possible to do it for minicart as there is no redirection and it's managed by ajax.
– LoicTheAztec
Nov 24 '18 at 10:31
add a comment |
WC_Cartget_remove_url()method is deprecated and replaced bywc_get_cart_remove_url()function.
It can be used as follow:
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Get the remove Url for the current cart item
$remove_url = wc_get_cart_remove_url( $cart_item_key );
}
this will give you an url like: https://www.example.com/cart/?removed_item=1…
Now to make changes on this Url, you can use woocommerce_get_remove_url dedicated filter hook, like in this example:
add_filter( 'woocommerce_get_remove_url', 'custom_item_remove_url', 10, 1 );
function custom_item_remove_url( $remove_url ) {
$cart_page_url = wc_get_page_permalink( 'cart' );
$replacement_url = wc_get_page_permalink( 'shop' ); // Shop page
// Change URL to shop page + remove Url query vars
$remove_url = str_replace($cart_page_url, $replacement_url, $remove_url);
return $remove_url;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
this will give you an url like: https://www.example.com/shop/?removed_item=1…
WC_Cartget_remove_url()method is deprecated and replaced bywc_get_cart_remove_url()function.
It can be used as follow:
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Get the remove Url for the current cart item
$remove_url = wc_get_cart_remove_url( $cart_item_key );
}
this will give you an url like: https://www.example.com/cart/?removed_item=1…
Now to make changes on this Url, you can use woocommerce_get_remove_url dedicated filter hook, like in this example:
add_filter( 'woocommerce_get_remove_url', 'custom_item_remove_url', 10, 1 );
function custom_item_remove_url( $remove_url ) {
$cart_page_url = wc_get_page_permalink( 'cart' );
$replacement_url = wc_get_page_permalink( 'shop' ); // Shop page
// Change URL to shop page + remove Url query vars
$remove_url = str_replace($cart_page_url, $replacement_url, $remove_url);
return $remove_url;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
this will give you an url like: https://www.example.com/shop/?removed_item=1…
edited Nov 23 '18 at 20:33
answered Nov 23 '18 at 19:36
LoicTheAztecLoicTheAztec
85.2k136095
85.2k136095
instead shop i want to redirect to cart and i have change into your code its not working
– R.K.Bhardwaj
Nov 24 '18 at 6:50
on my mini cart when i remove the cart item its not redirecting to view cart page this is the problem with your code the URL showing bottom but its not redirecting to view cart page
– R.K.Bhardwaj
Nov 24 '18 at 8:15
@R.K.Bhardwaj It's not possible to do it for minicart as there is no redirection and it's managed by ajax.
– LoicTheAztec
Nov 24 '18 at 10:31
add a comment |
instead shop i want to redirect to cart and i have change into your code its not working
– R.K.Bhardwaj
Nov 24 '18 at 6:50
on my mini cart when i remove the cart item its not redirecting to view cart page this is the problem with your code the URL showing bottom but its not redirecting to view cart page
– R.K.Bhardwaj
Nov 24 '18 at 8:15
@R.K.Bhardwaj It's not possible to do it for minicart as there is no redirection and it's managed by ajax.
– LoicTheAztec
Nov 24 '18 at 10:31
instead shop i want to redirect to cart and i have change into your code its not working
– R.K.Bhardwaj
Nov 24 '18 at 6:50
instead shop i want to redirect to cart and i have change into your code its not working
– R.K.Bhardwaj
Nov 24 '18 at 6:50
on my mini cart when i remove the cart item its not redirecting to view cart page this is the problem with your code the URL showing bottom but its not redirecting to view cart page
– R.K.Bhardwaj
Nov 24 '18 at 8:15
on my mini cart when i remove the cart item its not redirecting to view cart page this is the problem with your code the URL showing bottom but its not redirecting to view cart page
– R.K.Bhardwaj
Nov 24 '18 at 8:15
@R.K.Bhardwaj It's not possible to do it for minicart as there is no redirection and it's managed by ajax.
– LoicTheAztec
Nov 24 '18 at 10:31
@R.K.Bhardwaj It's not possible to do it for minicart as there is no redirection and it's managed by ajax.
– LoicTheAztec
Nov 24 '18 at 10:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451684%2fchange-remove-cart-item-url-in-woocommerce%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown