A shortcode to display availability date/time on pre-order products can help to create custom layouts for product pages using visual page builders.
It would be great to have all the custom meta information exposed through shortcodes.
Open
Last updated: September 30, 2021
Log in to comment on this feature request.
A shortcode is definitely cleaner than the custom PHP snippet above, especially since that only works if you’re comfortable dropping code into a page builder — not every store owner is.
Smart Pre-Order Manager for WooCommerce includes a shortcode to display the availability date/time on pre-order products, so you can drop it directly into visual page builders without writing custom code.
Happy to help if you have questions about setting it up.
I am using Oxygen page builder and created this code to fetch and display the single product page message, which you can customize in your Pre-Orders settings:
<?php
if ( function_exists( 'wc_get_product' ) ) {
// Get the WC_Product object
$product_id = get_the_ID();
$product = wc_get_product( $product_id );
// Now check and get the message
$message = get_option( 'wc_pre_orders_single_product_message' );
if ( ! empty( $message ) && is_a( $product, 'WC_Product' ) ) {
// Check if the product is available for pre-order (use the appropriate method from the plugin)
if ( WC_Pre_Orders_Product::product_can_be_pre_ordered( $product ) ) {
// Replace placeholders with actual data if available
$availability_date = WC_Pre_Orders_Product::get_localized_availability_date( $product );
$availability_time = WC_Pre_Orders_Product::get_localized_availability_time( $product );
$message = str_replace( '{availability_date}', $availability_date, $message );
$message = str_replace( '{availability_time}', $availability_time, $message );
// Output the sanitized message
echo '’ . esc_html( $message ) . ”;
}
}
}
?>
Please keep in mind that this is specific to my use case and will most likely require additional modifications for yours. But, I am hoping this is a solid starting point for you!