Skip to content

Instantly share code, notes, and snippets.

@SiR-DanieL
Created November 29, 2017 06:06
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
functions.php
add_filter( 'body_class', 'add_preorder_class' );
add_filter( 'post_class', 'add_preorder_class' );
function add_preorder_class( $classes ) {
global $post;
$product = wc_get_product( $post->ID );
if ( $product && 'yes' === get_post_meta( $product->get_id(), '_wc_pre_orders_enabled', true ) ) {
$classes[] = 'pre-order';
}
return $classes;
}
add_action( 'woocommerce_before_shop_loop_item_title', 'show_preorder_badge' );
add_action( 'woocommerce_before_single_product_summary', 'show_preorder_badge' );
function show_preorder_badge() {
global $post, $product;
?>
<?php if ( 'yes' === get_post_meta( $product->get_id(), '_wc_pre_orders_enabled', true ) ) : ?>
<?php echo '<span class="onsale pre-order">' . esc_html__( 'Pre-Order!', 'domain' ) . '</span>'; ?>
<?php endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment