简体   繁体   中英

Conditional tag for WooCommerce Pre-Order Products

I'm looking for a way to conditionally target products that are in Pre-order status. I'm using the WooCommerce Pre-Orders plugin. https://woocommerce.com/products/woocommerce-pre-orders/

I haven't been able to find any conditional tags in their documentation and their customer service wasn't able to help.

if (is_wc_pre_order()) {
    //do something...
}

Looking at their documentation, I was guess that the pre order capability for a product is saved as meta. If you ask support what the meta key is they should tell you, however, if you start talking about customizations they can be quite quick to say they can't help.

Looking at an old copy I have and assuming the meta key has not changed you should be able to use the following conditional:

$some_product_id = 99;
$product = wc_get_product( $some_product_id );

if( 'yes' === $product->get_meta( '_wc_pre_orders_enabled' ) ) {
   // This is a pre-order enabled product
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM