Mailchimp Banner | Q2 2024

added by Latoya

Product Icon

WooCommerce Pre-Orders

by  Woo
Allow customers to order products before they are available.

Shortcode to display availability date/time on pre-order products

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.

Author

Current Status

Open

Last updated: September 30, 2021

1 comment

Log in to comment on this feature request.

  1. mattdd4fd6a08da says:

    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!