How to display product lead times elsewhere on your site
The WooCommerce Lead Time plugin displays product lead times on the single product page. To ensure that the plugin works with all themes, we have coded it so that the lead time will only appear on the single product page, and not any other pages where your theme shows stock information.
We understand that you may sometimes wish to show lead times outside of the single product page. This article provides a choice of two methods for how to do this.
Using WooCommerce Product Table
The simplest way to display lead times away from the single product page is to use our other plugin, WooCommerce Product Table.
WooCommerce Product Table lets you list any or all of your products anywhere on your site. You can either add it to standard pages in WordPress, or to your shop and category page template.
When you use WooCommerce Lead Time together with WooCommerce Product Table, you can add a
lead-time column which displays the lead time within the product table.
Using WooCommerce Quick View Pro
If you don’t want to list products in a table, then you can use another Barn2 plugin – WooCommerce Quick View Pro. This is also designed to work with WooCommerce Lead Time.
The plugin adds quick view buttons to your shop and category pages, allowing customers to view product information and purchase from a quick view lightbox instead of the single product page. Your lead times will appear in the lightbox, so it’s an ideal way to show the lead time away from the product page.
Doing it programmatically
Alternatively, we have provided a template function so that you (or your developer) can display the lead time anywhere on your site.
Please note that this code is aimed at developers. If you don’t know how to use it, then we recommend posting a job on Codeable where one of their pre-approved WordPress experts will send you a quote. We have partnered with them to provide customizations for our plugins.
You can retrieve the product lead time for custom display by using one of the following template functions:
- wclt_get_lead_time – retrieves the lead time with the the suffix and prefix.
- wclt_get_lead_time_raw – retrieves the lead time without the the suffix and prefix.
As an example, below we retrieve the lead time within a product loop.
$product = wc_get_product( get_the_ID() ); $lead_time = wclt_get_lead_time( $product );