--- gid: c13316c6-44c3-4ba1-9fca-f99d239c173f title: Hide action and block extensions description: Learn how to conditionally hide action and block extensions in the Shopify admin. --- This guide is the final part in a five-part tutorial series on how to build a feature using admin action and block extensions. Before starting this guide, you'll need to build or copy the code for the issue tracker action and block from the [previous section](/docs/apps/build/admin/actions-blocks/connect-app-backend) of the tutorial. Alternatively, you can complete this section immediately after completing the [Build an admin action](/docs/apps/build/admin/actions-blocks/build-admin-action) and [Build an admin block](/docs/apps/build/admin/actions-blocks/build-admin-block) tutorials. So far you've created an admin action and block extension that allows merchants to create and track issues in their Shopify admin. In the previous tutorial, you connected the extension to your app's backend to store and retrieve issue data. In this tutorial, you'll learn how to hide the extension when it's not relevant to the target. To demonstrate conditional logic, we'll check the variant count of a product to determine if the extension should be visible. If the product has more than one variant, then the extension will be visible. If the product has only one variant, then the extension will be hidden. ## What you'll learn In this tutorial, you'll learn how to do the following tasks: - Minimize the admin block extension when it's not relevant to the target. - Hide the menu item that launches the admin action extension when it's not relevant to the target. Scaffold an app with the `write_products` access scope that uses [Shopify CLI 3.71 or higher](/docs/api/shopify-cli#upgrade). - If you created a Remix app, then the `write_products` access scope is automatically granted to your app. - If you created an extension-only app, then you need to explicitly grant the `write_products` access scope to your [custom app](/docs/apps/auth/access-token-types/admin-app-access-tokens#changing-api-scopes). ## Collapse an admin block extension If an admin block is not relevant on a page, then you can collapse it to minimize disruption for merchants, while still enabling them to see that they have pinned it to the page. To minimize a block extension, you can return `null` inside the `AdminBlock` component of your block extension. ### Use the getIssues function to determine if the block extension should be visible. Initialize a state variable called `shouldRender` and set it to `false`. You're already using the `getIssues` function to get metafield values. Using the same function, check if the product has more than one variant. If it does, then set the `shouldRender` state to `true`. ### Conditionally return JSX content based on the result of the getProductVariants function. If `shouldRender` is `true`, then render the block's content. If it's `false`, then return `null` to collapse the block. Use the `collapsedSummary` to provide meaningful information to the merchant about why the block is collapsed. ### Hide an admin action extension Hiding an action extension uses a second script to control the visibility of the action in the **More Actions** menu. This script only runs after the page is loaded and doesn't maintain state. Add a field to your TOML file to specify the path to the `shouldRender` script. Create a `shouldRender.js` file in the same `src` directory as the extension that you want to control. Specify the type of the global `shopify` object by adding a TypeScript triple slash directive to the top of the `shouldRender.js` file. Use the `should-render` target of the extension that you want to control. So, for an extensions with the target `admin.product-details.action.render`, the `should-render` target would be `admin.product-details.action.should-render`. Register your module using the global `shopify.extend` method. Create a function called `getProductVariants` to fetch variants of the product in your `utils.js` file. Use the `getProductVariants` function to determine the number of variants on the product. Return an object with a key of `display` and a Boolean value to control whether the action extension menu item is visible. ## Tutorial complete! Congratulations! You learned how to hide admin block and admin extensions when they are not relevant to a given target. Keep the momentum going with these related resources. #### Admin extension APIs Learn about the admin UI extension APIs. #### Participate File any issues or feature requests on the UI Extensions GitHub repository. #### Deploy Learn how to deploy your extension to merchants.