woocommerce offtopic – WC Bootstrap offcanvas sidebar – all links removed but WHY?


I wanted to move the Woocommerce shop sidebar into a bootstrap offcanvas block, to make it a better fit for mobile. In this I’ve succeeded however in doing so the links on each filter option have been removed and I have no idea why.

This is the code I’ve implmented, and which successfully creates a shortcode that I am using in sidebar.php, to replace the original, get_sidebar(‘shop’).

// Get sidebar content
function get_dynamic_sidebar($index = 1)
  $sidebar_contents = ob_get_clean();
  return $sidebar_contents;

// Register offcanvas sidebar
function offcanvas()
  $args = [
    'id' => 'offcanvasshop',
    'name' => __('Offcanvas Shop', 'woocommerce'),
add_action('widgets_init', 'offcanvas');

// Register sidebar shortcode
function get_shop_offcanvas_sidebar()
  $output="<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvas-shopsidebar"><div class="offcanvas-header cursor-pointer hover bg-light text-primary" data-bs-dismiss="offcanvas">" .
    esc_html__('Cancel', 'woocommerce') .
    ' <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="var(--bs-primary)"><path fill="none" d="M0 0h24v24H0z"/><path d="M13.172 12l-4.95-4.95 1.414-1.414L16 12l-6.364 6.364-1.414-1.414z"/></svg></div><div class="offcanvas-body"><div class="widget_shop_filters">' .
    get_dynamic_sidebar('offcanvasshop') .
  return $output;
add_shortcode('shop_offcanvas_sidebar', 'get_shop_offcanvas_sidebar');

Why are all the links being removed by this?

gpcola 3 months 2021-07-21T20:22:15-05:00 0 Answers 0 views 0

Leave an answer