WooCommerce: Remove “Create shipping label” Ad @ Single Order Admin Page

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!

Annoying, right?

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        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @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:

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *