Skip to content

Instantly share code, notes, and snippets.

@SiR-DanieL
Last active October 30, 2023 10:14
Show Gist options
  • Save SiR-DanieL/46c568ebc9a72e8fffa3166c4ef02e90 to your computer and use it in GitHub Desktop.
Save SiR-DanieL/46c568ebc9a72e8fffa3166c4ef02e90 to your computer and use it in GitHub Desktop.
Customize Pre-Order Products
<?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