# Code Snippets

**URL:** https://community.mainwp.com/c/howto/code-snippets/18.md

[Latest](https://community.mainwp.com/latest.md) · [Categories](https://community.mainwp.com/categories.md) · [Tags](https://community.mainwp.com/tags.md)

---

## [About the Code Snippets category](https://community.mainwp.com/t/about-the-code-snippets-category/40)

<div class="topic-metadata">

**Author:** [@dennis](https://community.mainwp.com/u/dennis)\
**Replies:** 0\
**Last updated:** [January 6, 2020, 4:48pm UTC](https://community.mainwp.com/t/about-the-code-snippets-category/40 "2020-01-06T16:48:48Z")

</div>

Tutorial topics that describe how to set up and use the Code Snippet Extension. Topics in this category may only be created by trust level 2 and up.

---

## [Add a custom link to the toolbar menu in Gravity Forms](https://community.mainwp.com/t/add-a-custom-link-to-the-toolbar-menu-in-gravity-forms/10362)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [July 11, 2025, 3:46pm UTC](https://community.mainwp.com/t/add-a-custom-link-to-the-toolbar-menu-in-gravity-forms/10362 "2025-07-11T15:46:32Z")

</div>

Add a custom link to the toolbar menu in Gravity Forms. Snippet Type Execute on Child Sites Snippet add\_filter( 'gform\_toolbar\_menu', 'add\_custom\_toolbar\_menu\_item', 10, 2 ); function add\_custom\_toolbar\_menu\_item( $m…

---

## [Disable canonical redirect in WordPress](https://community.mainwp.com/t/disable-canonical-redirect-in-wordpress/10358)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [July 10, 2025, 9:05pm UTC](https://community.mainwp.com/t/disable-canonical-redirect-in-wordpress/10358 "2025-07-10T21:05:05Z")

</div>

Disable canonical redirect in WordPress. Snippet Type Execute on Child Sites Snippet # Disable canonical redirect completely remove\_action( 'template\_redirect', 'redirect\_canonical' ); # Disable "old slug" redirectio…

---

## [Preselect and restrict to one city and state on checkout in WooCommerce](https://community.mainwp.com/t/preselect-and-restrict-to-one-city-and-state-on-checkout-in-woocommerce/10355)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [July 9, 2025, 5:07pm UTC](https://community.mainwp.com/t/preselect-and-restrict-to-one-city-and-state-on-checkout-in-woocommerce/10355 "2025-07-09T17:07:15Z")

</div>

Preselect and restrict to one city and state on checkout in WooCommerce. Snippet Type Execute on Child Sites Snippet // default checkout country add\_filter( 'default\_checkout\_billing\_country', 'change\_default\_checkou…

---

## [Remove the payments method section from my account in WooCommerce](https://community.mainwp.com/t/remove-the-payments-method-section-from-my-account-in-woocommerce/10354)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [July 7, 2025, 8:50pm UTC](https://community.mainwp.com/t/remove-the-payments-method-section-from-my-account-in-woocommerce/10354 "2025-07-07T20:50:22Z")

</div>

Remove the payments method section from my account in WooCommerce. Snippet Type Execute on Child Sites Snippet add\_filter( 'woocommerce\_account\_menu\_items', 'remove\_payment\_methods\_my\_account', 999 ); function remove…

---

## [Hide prices unless user is logged in WooCommerce](https://community.mainwp.com/t/hide-prices-unless-user-is-logged-in-woocommerce/10347)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [July 3, 2025, 9:48pm UTC](https://community.mainwp.com/t/hide-prices-unless-user-is-logged-in-woocommerce/10347 "2025-07-03T21:48:51Z")

</div>

Hide prices unless user is logged in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/WooCommerce/h…

---

## [Normalize the search values in Relevanssi](https://community.mainwp.com/t/normalize-the-search-values-in-relevanssi/10346)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [July 3, 2025, 9:37pm UTC](https://community.mainwp.com/t/normalize-the-search-values-in-relevanssi/10346 "2025-07-03T21:37:24Z")

</div>

Normalize the search values in Relevanssi. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/Relevanssi/normalize…

---

## [Cache secondary languages from TranslatePress in WP Rocket](https://community.mainwp.com/t/cache-secondary-languages-from-translatepress-in-wp-rocket/10340)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [July 1, 2025, 10:07pm UTC](https://community.mainwp.com/t/cache-secondary-languages-from-translatepress-in-wp-rocket/10340 "2025-07-01T22:07:24Z")

</div>

Cache secondary languages from TranslatePress in WP Rocket. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/WP%…

---

## [Disable the email change email notification for a specific user in WordPress](https://community.mainwp.com/t/disable-the-email-change-email-notification-for-a-specific-user-in-wordpress/10338)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 30, 2025, 8:48pm UTC](https://community.mainwp.com/t/disable-the-email-change-email-notification-for-a-specific-user-in-wordpress/10338 "2025-06-30T20:48:54Z")

</div>

Disable the email change email notification for a specific user in WordPress. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%…

---

## [Use ACF field as fallback for excerpt in Advanced Custom Fields](https://community.mainwp.com/t/use-acf-field-as-fallback-for-excerpt-in-advanced-custom-fields/10325)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 26, 2025, 7:13pm UTC](https://community.mainwp.com/t/use-acf-field-as-fallback-for-excerpt-in-advanced-custom-fields/10325 "2025-06-26T19:13:02Z")

</div>

Use ACF field as fallback for excerpt in Advanced Custom Fields. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20sit…

---

## [Taxonomy ordering in Ajax Load More](https://community.mainwp.com/t/taxonomy-ordering-in-ajax-load-more/10323)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 25, 2025, 4:47pm UTC](https://community.mainwp.com/t/taxonomy-ordering-in-ajax-load-more/10323 "2025-06-25T16:47:30Z")

</div>

Taxonomy ordering in Ajax Load More. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/Ajax%20Load%20More/taxonom…

---

## [Change the COD order status to on hold in WooCommerce](https://community.mainwp.com/t/change-the-cod-order-status-to-on-hold-in-woocommerce/10321)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 24, 2025, 10:02pm UTC](https://community.mainwp.com/t/change-the-cod-order-status-to-on-hold-in-woocommerce/10321 "2025-06-24T22:02:56Z")

</div>

Change the COD order status to on hold in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/WooComme…

---

## [Remove out of stock products from the cart and checkout in WooCommerce](https://community.mainwp.com/t/remove-out-of-stock-products-from-the-cart-and-checkout-in-woocommerce/10318)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 23, 2025, 8:14pm UTC](https://community.mainwp.com/t/remove-out-of-stock-products-from-the-cart-and-checkout-in-woocommerce/10318 "2025-06-23T20:14:20Z")

</div>

Remove out of stock products from the cart and checkout in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20chil…

---

## [Display content in the confirmation and then redirect to a URL in Gravity Forms](https://community.mainwp.com/t/display-content-in-the-confirmation-and-then-redirect-to-a-url-in-gravity-forms/10315)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 20, 2025, 4:17pm UTC](https://community.mainwp.com/t/display-content-in-the-confirmation-and-then-redirect-to-a-url-in-gravity-forms/10315 "2025-06-20T16:17:26Z")

</div>

Display content in the confirmation and then redirect to a URL in Gravity Forms. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%2…

---

## [Disable the DNS preconnect to external domains feature in WP Rocket](https://community.mainwp.com/t/disable-the-dns-preconnect-to-external-domains-feature-in-wp-rocket/10312)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 18, 2025, 7:35pm UTC](https://community.mainwp.com/t/disable-the-dns-preconnect-to-external-domains-feature-in-wp-rocket/10312 "2025-06-18T19:35:41Z")

</div>

Disable the DNS preconnect to external domains feature in WP Rocket. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%2…

---

## [Remove the sku word in Ajax Search for WooCommerce](https://community.mainwp.com/t/remove-the-sku-word-in-ajax-search-for-woocommerce/10311)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 17, 2025, 5:57pm UTC](https://community.mainwp.com/t/remove-the-sku-word-in-ajax-search-for-woocommerce/10311 "2025-06-17T17:57:47Z")

</div>

Remove the sku word in Ajax Search for WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/Ajax%20Sear…

---

## [Include product brands in search results in Advanced Woo Search](https://community.mainwp.com/t/include-product-brands-in-search-results-in-advanced-woo-search/10310)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 17, 2025, 5:50pm UTC](https://community.mainwp.com/t/include-product-brands-in-search-results-in-advanced-woo-search/10310 "2025-06-17T17:50:32Z")

</div>

Include product brands in search results in Advanced Woo Search. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20sit…

---

## [Remove the billing email address on profile update in WooCommerce](https://community.mainwp.com/t/remove-the-billing-email-address-on-profile-update-in-woocommerce/10306)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 13, 2025, 6:34pm UTC](https://community.mainwp.com/t/remove-the-billing-email-address-on-profile-update-in-woocommerce/10306 "2025-06-13T18:34:40Z")

</div>

Remove the billing email address on profile update in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20s…

---

## [Disable the filter edit button for logged-in admin users in Ajax Load More](https://community.mainwp.com/t/disable-the-filter-edit-button-for-logged-in-admin-users-in-ajax-load-more/10300)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 11, 2025, 4:56pm UTC](https://community.mainwp.com/t/disable-the-filter-edit-button-for-logged-in-admin-users-in-ajax-load-more/10300 "2025-06-11T16:56:39Z")

</div>

Disable the filter edit button for logged-in admin users in Ajax Load More. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20…

---

## [Change the submit button text in Ajax Load More](https://community.mainwp.com/t/change-the-submit-button-text-in-ajax-load-more/10299)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 11, 2025, 4:52pm UTC](https://community.mainwp.com/t/change-the-submit-button-text-in-ajax-load-more/10299 "2025-06-11T16:52:36Z")

</div>

Change the submit button text in Ajax Load More. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/Ajax%20Load%20…

---

## [Move Variation description from original location to single product summary in WooCommerce](https://community.mainwp.com/t/move-variation-description-from-original-location-to-single-product-summary-in-woocommerce/10295)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 10, 2025, 5:28pm UTC](https://community.mainwp.com/t/move-variation-description-from-original-location-to-single-product-summary-in-woocommerce/10295 "2025-06-10T17:28:15Z")

</div>

Move Variation description from original location to single product summary in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20func…

---

## [Add content above the registration fields in BuddyPress](https://community.mainwp.com/t/add-content-above-the-registration-fields-in-buddypress/10290)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 6, 2025, 8:07pm UTC](https://community.mainwp.com/t/add-content-above-the-registration-fields-in-buddypress/10290 "2025-06-06T20:07:46Z")

</div>

Add content above the registration fields in BuddyPress. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/BuddyP…

---

## [Add WooCommerce brand term to admin order details above product name in WooCommerce](https://community.mainwp.com/t/add-woocommerce-brand-term-to-admin-order-details-above-product-name-in-woocommerce/10278)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 4, 2025, 8:48pm UTC](https://community.mainwp.com/t/add-woocommerce-brand-term-to-admin-order-details-above-product-name-in-woocommerce/10278 "2025-06-04T20:48:26Z")

</div>

Add WooCommerce brand term to admin order details above product name in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20…

---

## [On the checkout page add a link on the product image in WooCommerce](https://community.mainwp.com/t/on-the-checkout-page-add-a-link-on-the-product-image-in-woocommerce/10272)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 3, 2025, 7:51pm UTC](https://community.mainwp.com/t/on-the-checkout-page-add-a-link-on-the-product-image-in-woocommerce/10272 "2025-06-03T19:51:05Z")

</div>

On the checkout page add a link on the product image in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%2…

---

## [Add a proceed to checkout button after an item is added to cart in WooCommerce](https://community.mainwp.com/t/add-a-proceed-to-checkout-button-after-an-item-is-added-to-cart-in-woocommerce/10271)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [June 3, 2025, 7:41pm UTC](https://community.mainwp.com/t/add-a-proceed-to-checkout-button-after-an-item-is-added-to-cart-in-woocommerce/10271 "2025-06-03T19:41:26Z")

</div>

Add a proceed to checkout button after an item is added to cart in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20…

---

## [Enable Safe Mode in Really Simple SSL](https://community.mainwp.com/t/enable-safe-mode-in-really-simple-ssl/171)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [January 8, 2020, 3:53am UTC](https://community.mainwp.com/t/enable-safe-mode-in-really-simple-ssl/171 "2020-01-08T03:53:54Z")

</div>

Enable safe mode in Really Simple SSL by using this code snippet: Snippet Type Save to wp-config.php Snippet define(“RSSSL\_SAFE\_MODE”, true);

---

## [Hide the admin menu dynamically based on site domain in Advanced Custom Fields](https://community.mainwp.com/t/hide-the-admin-menu-dynamically-based-on-site-domain-in-advanced-custom-fields/10256)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [May 29, 2025, 9:28pm UTC](https://community.mainwp.com/t/hide-the-admin-menu-dynamically-based-on-site-domain-in-advanced-custom-fields/10256 "2025-05-29T21:28:04Z")

</div>

Hide the admin menu dynamically based on site domain in Advanced Custom Fields. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20…

---

## [Fix the fetch patterns action issue in WooCommerce](https://community.mainwp.com/t/fix-the-fetch-patterns-action-issue-in-woocommerce/10255)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [May 28, 2025, 7:54pm UTC](https://community.mainwp.com/t/fix-the-fetch-patterns-action-issue-in-woocommerce/10255 "2025-05-28T19:54:13Z")

</div>

Fix the fetch patterns action issue in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20child%20site/WooCommerce…

---

## [Allow misspelling fix only for words with one typo in Advanced Woo Search](https://community.mainwp.com/t/allow-misspelling-fix-only-for-words-with-one-typo-in-advanced-woo-search/10254)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [May 27, 2025, 10:34pm UTC](https://community.mainwp.com/t/allow-misspelling-fix-only-for-words-with-one-typo-in-advanced-woo-search/10254 "2025-05-27T22:34:14Z")

</div>

Allow misspelling fix only for words with one typo in Advanced Woo Search. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20c…

---

## [Conditionally hide a product variation based on user role in WooCommerce](https://community.mainwp.com/t/conditionally-hide-a-product-variation-based-on-user-role-in-woocommerce/10253)

<div class="topic-metadata">

**Author:** [@sebastian-moran](https://community.mainwp.com/u/sebastian-moran)\
**Replies:** 0\
**Last updated:** [May 27, 2025, 5:05pm UTC](https://community.mainwp.com/t/conditionally-hide-a-product-variation-based-on-user-role-in-woocommerce/10253 "2025-05-27T17:05:34Z")

</div>

Conditionally hide a product variation based on user role in WooCommerce. Snippet Type Execute on Child Sites Snippet https://github.com/mainwp/Code-Snippets-Functions/blob/master/Execute%20a%20function%20on%20a%20ch…

[Next page](https://community.mainwp.com/c/howto/code-snippets/18.md?page=1)
