Halloween Sale 15% off Ends in See the plans
PHP

"Pre-Order" Badge for Backorder Products

Labels products that are out of stock but allow backorders with a "Pre-order" badge in the shop and on product pages, so buyers know shipping will be later.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_backorder_badge = 'Pre-order'; // Badge text.

$wpide_backorder_badge_html = function () use ( $wpide_backorder_badge ) {
    global $product;

    if ( $product instanceof WC_Product && $product->is_on_backorder() ) {
        printf( '<span class="wpide-backorder-badge">%s</span>', esc_html( $wpide_backorder_badge ) );
    }
};

add_action( 'woocommerce_before_shop_loop_item_title', $wpide_backorder_badge_html, 9 );
add_action( 'woocommerce_before_single_product_summary', $wpide_backorder_badge_html, 9 );

add_action( 'wp_head', function () {
    if ( is_woocommerce() ) {
        echo '<style>.woocommerce ul.products li.product,.woocommerce div.product{position:relative}.wpide-backorder-badge{position:absolute;bottom:.5em;left:.5em;z-index:9;padding:.25em .6em;border-radius:3px;background:#6d28d9;color:#fff;font-size:.8em;font-weight:600}</style>';
    }
} );

Notes

Shows on products whose stock status is "On backorder"; change the text to "Backorder" or "Ships later" if you prefer.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.