Created
May 28, 2019 08:44
-
-
Save vdwijngaert/6813a5548830e4a0b0f0e6f42cf05e8f to your computer and use it in GitHub Desktop.
Undo WooCommerce tab removal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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