GBO Posted November 22, 2023 Share Posted November 22, 2023 Hello I hope you can help. I have a WordPress Woocommerce website where I've added a short code snippet to change the standard "No products Found" message. At the bottom of the message, I would like to add a short code form which has been produced through the WPForms plugin. The PHP code as below: <?php add_action( 'woocommerce_no_products_found', function(){ remove_action( 'woocommerce_no_products_found', 'wc_no_products_found', 10 ); // HERE change your message below $message = __( 'Adding parts to the site is an ongoing effort. The part you’re searching for may be within our range but not yet uploaded. If you are unable to find what you are looking for, please fill in our contact form below. Alternatively, email us at sales@crushersparesltd.co.uk , call us on 0044 1443 228329 or via contact us via WhatsApp on 0044 732473727.', 'woocommerce' ); echo ' ' . $message .' '; }, 9 ); The WPForms shortcode: [wpforms id="1385"]. You can view the message through this link https://www.offershubdirect.com/product-category/model/lt106/. I have attached an image of what I'm looking for. Gary Quote Link to comment https://forums.phpfreaks.com/topic/317467-adding-a-short-code-form-to-a-message/ Share on other sites More sharing options...
Solution Olumide Posted November 22, 2023 Solution Share Posted November 22, 2023 To integrate the WPForms shortcode into your custom WooCommerce "No products found" message, you can modify the code as follows: add_action( 'woocommerce_no_products_found', function(){ remove_action( 'woocommerce_no_products_found', 'wc_no_products_found', 10 ); // WooCommerce custom message $woocommerce_message = __( 'Adding parts to the site is an ongoing effort. The part you’re searching for may be within our range but not yet uploaded. If you are unable to find what you are looking for, please fill in our contact form below. Alternatively, email us at sales@crushersparesltd.co.uk , call us on 0044 1443 228329 or contact us via WhatsApp on 0044 732473727.', 'woocommerce' ); // WPForms shortcode $wpforms_shortcode = do_shortcode('[wpforms id="1385"]'); // Output combined message and form echo ' ' . $woocommerce_message .' ' . $wpforms_shortcode .' '; }, 9 ); Quote Link to comment https://forums.phpfreaks.com/topic/317467-adding-a-short-code-form-to-a-message/#findComment-1613039 Share on other sites More sharing options...
GBO Posted November 22, 2023 Author Share Posted November 22, 2023 Brilliant. You are so skilful. It all works. Thank you very much. Gary Quote Link to comment https://forums.phpfreaks.com/topic/317467-adding-a-short-code-form-to-a-message/#findComment-1613045 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.