title: Woocommerce Continue Shopping Button Link to Last Product Category Page
body: <p>There are forum topics regarding custom continue shopping buttons, but there is nothing on how to link the custom button to the last product category page viewed. There is a plugin that gives the option for this; however, there is a flaw in that when the cart is refreshed, the button disappears. The following code works to create a custom message/button; however, I cannot figure out how to change the link from the shop page to the last product category page viewed:</p>
  
  <pre><code>/* Add Continue Shopping Button on Cart Page &amp; Checkout page*/
  add_action( 'woocommerce_before_cart_table', 
  'woo_add_continue_shopping_button_to_cart' );
  add_action( 'woocommerce_before_checkout_form', 
  'woo_add_continue_shopping_button_to_cart' );
  
  function woo_add_continue_shopping_button_to_cart() {
  $shop_page_url = "get_permalink( wc_get_page_id( 'shop' ) )";
  
  echo '&lt;div class="woocommerce-message"&gt;';
  echo ' &lt;a href="'.$shop_page_url.'" class="button wc-forwards"&gt;Continue 
  Shopping →&lt;/a&gt; Would you like some more prints?';
  echo '&lt;/div&gt;';
  }
  </code></pre>
  
  <p>Thank you in advance!
  J.</p>
  
  <p>Here is the code that the plugin uses to link (I think):</p>
  
  <pre><code>add_action( 'woocommerce_cart_is_empty', 'hpy_cs_output_notice', 1 );
  function hpy_cs_output_notice() {
  
  $display_empty = get_option( 'hpy_cs_empty_cart_notice' );
  
  if ( $display_empty == 'yes' ) {
      $link = wc_custom_redirect_continue_shopping();
  
      $message = sprintf('&lt;a href="%s" class="button wc-forward"&gt;%s&lt;/a&gt; %s', 
  esc_url($link), esc_html__('Continue shopping', 'woocommerce'), 
  esc_html(get_option('hpy_cs_empty_cart_text', __('Your cart is empty.', '    
  $message = sprintf( \'&lt;a href="%s" class="button wc-forward"&gt;%s&lt;/a&gt; %s\', 
  esc_url( $link ), esc_html__( \'Continue shopping\', \'woocommerce\' ), 
  esc_html( get_option( \'hpy_cs_empty_cart_text\', __( \'Your cart is 
  empty.\', \'hpy_cshpy_cshpy_cs\' ) ) ) );
  '))));
  
      wc_print_notice($message);
  }
  
  }
  </code></pre>