Here we go again. It feels like the WooCommerce plugin has become the same as some of those free extensions you get from the repo that fill up the WordPress dashboard with ads, notices and banners.
This time around, let’s get rid of the “Print discounted shipping labels with a click. By clicking “Create shipping label”, WooCommerce Shipping will be installed and you agree to its Terms of Service. Create shipping label” banner that displays at the top (!) of the single order admin page when the status is processing or completed and shipping is required (see screenshot below).
Long live a world without ads!
PHP Snippet: Hide “Print discounted shipping labels with a click” WooCommerce Banner @ Edit Order Page
Of course, you can always click on the “dismiss” button and hide the banner:
But my point here is that I don’t want to display the banner in the first place.
A nice workaround, then, is to let WooCommerce know that we already clicked on that dismiss button, even before loading the page, and this should hide the banner forever.
By looking at the WooCommerce code, I found this after a bit of research (woocommerce/src/Internal/Admin/ShippingLabelBannerDisplayRules.php):
/**
* Checks if the banner was not dismissed by the user.
*
* @return bool
*/
private function banner_not_dismissed() {
$dismissed_timestamp_ms = get_option( 'woocommerce_shipping_dismissed_timestamp' );
if ( ! is_numeric( $dismissed_timestamp_ms ) ) {
return true;
}
$dismissed_timestamp_ms = intval( $dismissed_timestamp_ms );
$dismissed_timestamp = intval( round( $dismissed_timestamp_ms / 1000 ) );
$expired_timestamp = $dismissed_timestamp + 24 * 60 * 60; // 24 hours from click time
$dismissed_for_good = -1 === $dismissed_timestamp_ms;
$dismissed_24h = time() < $expired_timestamp;
return ! $dismissed_for_good && ! $dismissed_24h;
}
This is the PHP line that matters:
$dismissed_timestamp_ms = get_option( 'woocommerce_shipping_dismissed_timestamp' );
Apparently, the “dismiss” button assigns a timestamp to this custom WordPress option.
Also, we need to consider this bit:
if ( ! is_numeric( $dismissed_timestamp_ms ) ) {
return true;
}
Which says: “unless the option value is numeric”, do not consider dismissing the banner.
Finally, this line:
$dismissed_for_good = -1 === $dismissed_timestamp_ms;
Which means, if I assign “-1”, it’s dismissed for good!
So, let’s override it by forcing the option value to “-1” with the “pre_option_OPTIONNAME” WordPress filter:
/**
* @snippet Dismiss Shipping Label Meta Box @ Woo Order Admin Page
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 9
* @community https://businessbloomer.com/club/
*/
add_filter( 'pre_option_woocommerce_shipping_dismissed_timestamp', 'bbloomer_hide_shipping_label_banner' );
function bbloomer_hide_shipping_label_banner() {
return -1;
}
Banner is gone now: