Skip to content

Instantly share code, notes, and snippets.

@jarcos
Last active March 2, 2017 15:39
Show Gist options
  • Save jarcos/51855df75b71a4c8cf73b4b044f93d7b to your computer and use it in GitHub Desktop.
Save jarcos/51855df75b71a4c8cf73b4b044f93d7b to your computer and use it in GitHub Desktop.
Returns to product category page after click on Continue Shopping button
<?php
/**
* It takes the first category find on the array.
* Ideally for stores with products with a single category.
*/
add_filter( 'woocommerce_continue_shopping_redirect', 'wa_custom_redirect_continue_shopping' );
function wa_custom_redirect_continue_shopping() {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$ids = array();
foreach($items as $item => $values) {
$_product = $values['data']->post;
$ids[] = $_product->ID;
}
$last_item = end($ids);
$terms = get_the_terms( $last_item, 'product_cat' );
return get_term_link( $terms[0]->term_id, 'product_cat' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment