Jump to content

Adding a short code form to a message


GBO
Go to solution Solved by Olumide,

Recommended Posts

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

php help.PNG

Link to comment
Share on other sites

  • Solution

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 );
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.