Community
Administrator
Staff member
So from our custom stock status code here : https://wphelpforums.com/threads/how-to-add-custom-woocommerce-stock-status-without-a-plugin.7325/
We now want to add a banner below the price on woocommerce products pages, but only for certain stock statuses.
To do that, we are going to add the below function, to use the "woocommerce_single_product_summary" hook and insert some Elementor Shortcodes , to get the elementor shortcodes, simply goto templates, create a new section with your banner in it. Then publish. Once published go back to the template page, and copy the shortcode and add it to this code.
So as you can see, we add different shortcodes/banners to 3 different stock statuses, Made to order, Delivery request and direct from factory.
Thanks to Adam from Rivmedia for this one
We now want to add a banner below the price on woocommerce products pages, but only for certain stock statuses.
To do that, we are going to add the below function, to use the "woocommerce_single_product_summary" hook and insert some Elementor Shortcodes , to get the elementor shortcodes, simply goto templates, create a new section with your banner in it. Then publish. Once published go back to the template page, and copy the shortcode and add it to this code.
PHP:
function display_elementor_template_for_custom_status() {
global $product;
// Ensure we are on a single product page
if ( is_product() ) {
// Check the stock status and display the corresponding shortcode
switch ( $product->get_stock_status() ) {
case 'made_to_order':
echo do_shortcode('[elementor-template id="127984"]'); // Replace 127984 with the correct Elementor template ID for Made to order
break;
case 'delivery_request':
echo do_shortcode('[elementor-template id="127995"]'); // Replace 127995 with the correct Elementor template ID for Delivery on Request
break;
case 'direct_factory':
echo do_shortcode('[elementor-template id="127996"]'); // Replace 127996 with the correct Elementor template ID for Direct from Factory
break;
}
}
}
add_action( 'woocommerce_single_product_summary', 'display_elementor_template_for_custom_status', 25 ); So as you can see, we add different shortcodes/banners to 3 different stock statuses, Made to order, Delivery request and direct from factory.
Thanks to Adam from Rivmedia for this one
