Add link to the WC category/tag pages to open WP Sheet Editor

This tutorial is for developers.

In this snippet, we’ll show you how to add a link to the WooCommerce category and tag pages in the front end, that will appear for administrators, and it will open the WP Sheet Editor with a filter to show rows related to the current category or tag.
The link will appear below the category/tag description, and it’s a good way to provide a shortcut to your administrators to quickly edit the products when they’re viewing the shop catalog in the front end.

<?php
add_action( "woocommerce_archive_description", "add_edit_archive_link_for_admins", 10, 0 );
function add_edit_archive_link_for_admins()
{
if (
current_user_can("manage_options") &&
(is_product_category() || is_product_tag())
) {
$term_id = get_queried_object_id();
$taxonomy = get_queried_object()->taxonomy;
$term = get_term($term_id, $taxonomy);
$slug = $term->slug;
$spreadsheet_url = add_query_arg(
[
"wpse_custom_filters" => [
"apply_to" => [$taxonomy . "--" . $slug],
],
],
// Replace this URL with the URL of your WP Sheet Editor
"http://site.com/wp-admin/admin.php?page=vgse-bulk-edit-product"
);
echo '<a href="' . esc_url_raw($spreadsheet_url) . '" style="display:block; margin-top:15px;">Edit This Archive</a>';
}
}

Do you need help?

You can receive instant help in the live chat during business hours, or you can contact us and we will help you via email.