Skip to content

Instantly share code, notes, and snippets.

@vdwijngaert
Created May 28, 2019 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdwijngaert/6813a5548830e4a0b0f0e6f42cf05e8f to your computer and use it in GitHub Desktop.
Save vdwijngaert/6813a5548830e4a0b0f0e6f42cf05e8f to your computer and use it in GitHub Desktop.
Undo WooCommerce tab removal
<?php
/**
* @param string $tab
* @param int $offendingPriority
*/
function my_prefix_undoTabRemoval($tab, $offendingPriority = 10)
{
static $filterName = 'woocommerce_product_tabs';
// Accessible variable for the tab content.
$tabContents = null;
add_filter($filterName, function ($tabs) use ($tab, &$tabContents) {
// Safely store the tab content (if available).
$tabContents = $tabs[$tab] ?? null;
return $tabs;
}, $offendingPriority - 1);
add_filter($filterName, function ($tabs) use ($tab, &$tabContents) {
if (null !== $tabContents && ! isset($tabs[$tab])) {
// Restore the tab.
$tabs[$tab] = $tabContents;
}
return $tabs;
}, $offendingPriority + 1);
}
add_action('init', function () {
my_prefix_undoTabRemoval('additional_information');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment