Last active
October 30, 2023 10:14
-
-
Save SirDarcanos/46c568ebc9a72e8fffa3166c4ef02e90 to your computer and use it in GitHub Desktop.
Customize Pre-Order Products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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