1

I am trying to replace the "add to cart" button in WordPress With "Send Inquiry", Which sends an Inquiry regarding the product, Bypass the Cart Option and use it in a Contact form,

Used a simple CSS to Disable the add to cart button.

I tried adding "contact form 7" form into each product, But that didn't sort out,

I am out of ideas,Can someone guide me on a path that might work.

1 Answer 1

2

I post this as an answer, since its to long for a comment.
I dont know if this will fit your needs, since its a little bit complicated and I also link to a seperate plugin which I used successfully.
So if the answer dont fit, feel free to vote another one!

You said you just disabled the add to cart button via CSS, but this is unsafe, because the button is still there only not visible. Instead you should remove the button via the available WooCommerce hooks, something like: (UPDATED)

// remove add to cart button for every product
add_action( 'init', 'prfx_remove_add_to_cart_button');
function prfx_remove_add_to_cart_button() {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); // catalog page
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); // single product page
}

Or you could also use a WooCommerce filter and disable the purchase of these products (add to cart button disappears), like:

add_filter('woocommerce_is_purchasable', 'prfx_is_product_purchasbale');
function prfx_is_product_purchasbale($purchasable, $product) {

    // you could check agains a meta option, or maybe if a shortcode exists in this product
    if ($product->id == 132) {
        $purchasable = false;
    }

    return $purchasable;
}

Anyway I realised a similar system using the following setup:

I used the following plugins:

  • Contact Form 7
  • Contact Form 7 Get and Show Parameter from URL (available here)

The "Contact Form 7 Get and Show Parameter from URL" plugin was last updated a long time ago and there already are some problems with this old code. Others and also I myself, created a fixed version of this plugin, for example here: https://github.com/LWS-Web/contact-form-7-get-and-show-parameter-from-url

The plugin can be used for the following:

There are times when using the Contact Form 7 WordPress plugin where you need to pass a parameter from the URL and into a hidden field or display it in the form. This plugin is great for passing things such as order numbers, selected packages, or even security information.

The idea is: Creating a link on the product page, which contains the product title and, for example, the ID of the product. If the link is clicked, the contact form will open, and the title and ID of the product are still available via URL parameters. The title and ID can than be shown on the form and mail.

Here is a summery of what I did:

1. Create a new Contact Form 7 form, and inserted it on a page with the slug product-inquiry.

2. Create a link on the single product page which looks like this for example:

<a href="<insert your home-url>/product-inquiry/?product-title=<insert your product-title>&product-id=<insert your product-id>">Product Inquiry</a>

So in the frontend/browser this link will look like/point to:
https://example.com/product-inquiry/?product-title=My Product&product-id=132

(UPDATE)
You should use WooCommerce hooks to insert the new button in place of the old button.
Also if you use variations, its get compicated fast.
For example, you could insert the inquiry button with something like this:

// add inquiry button into every product
// we use the same hooks as before, to insert the new content on the same spot
add_action( 'woocommerce_after_shop_loop_item', 'prfx_add_inquiry_button', 10); // catalog page
add_action( 'woocommerce_single_product_summary', 'prfx_add_inquiry_button', 30); // single product page
function prfx_add_inquiry_button() {

    $current_product_id = get_the_ID(); // get ID of the current post
    $current_product_title = get_the_title(); // get the title of the current post

    $product = wc_get_product( $current_product_id ); // get the product object

    // create a button for variable/variant products
    if ($product->is_type( 'variable' )) {

        $variations = $product->get_available_variations(); // get all available variations of the current product

        if ($variations) {
            foreach ($variations as $variation) {

                if ($variation['variation_is_active'] == 1) {

                    echo '<div>';

                    // use this to see all available data
                    // print_r($variation);

                    $variation_price_html = $variation['price_html']; // variation price html, for example "€150,00 incl. vat"
                    $variation_id = $variation['variation_id']; // variation ID, for example "2006"
                    $variation_title = get_the_title( $variation_id ); // variation title, for example "Beanie with Logo - red, medium"

                    // we create a button for each single available variation
                    echo '<a href="'.home_url('/product-inquiry').'/?product-title='.$variation_title.'&product-id='.$variation_id.'" class="button">';

                        echo $variation_title; // show title
                        echo '<br>';
                        echo $variation_price_html; // show price html

                    echo '</a>';

                    echo '</div><br>';

                }

            }
        }

    // create a button for simple products
    } elseif ($product->is_type( 'simple' )) { 

        echo '<a href="'.home_url('/product-inquiry').'/?product-title='.$current_product_title.'&product-id='.$current_product_id.'" class="button">';

            echo $current_product_title;

        echo '</a>';
    }

}

If you click the link, the page with the inquiryform opens, and you will see in the url, that the product title and also ID is available as parameters.

So now you can use some shortcodes (coming from the Contact Form 7 Get and Show Parameter from URL plugin) to show and work with these url parameters.

[getparam product-title] > Get the value of the "product-title" URL parameter-from-url. (not visible on frontend)
[showparam product-title] > SHOW/USE the value in the contact form.

[getparam product-id] ... same as above
[showparam product-id] ... same as above

3. Edit your inquiry form and insert some text with shortcodes on the form like:

[getparam product-title][getparam product-id]
<p>Inquiry for product: [showparam product-title] ([showparam product-id]) </p>

This will than show text on the frontend like Inquiry for product: My Product (132).

4. Last, edit the mail settings of the form. Here you can now use shortcodes like [product-title] and [product-id] to get these values into the send mail! The available shortcodes are listed on the top of the page.

8
  • Thank you so much for the idea,but still having issue with the way you mentioned to remove the add to cart button.
    – maxasela
    Commented Jun 18, 2019 at 10:41
  • Do you want to replace the "add to cart" button on every product, or just some products? If you want the inquiry button only on some specific products, these products should be identified with something ... for example a meta option/checkbox. With that you could check if the option is enabled in the woocommerce_is_purchasable function to disable the purchase.
    – LWS-Mo
    Commented Jun 19, 2019 at 7:29
  • on Every product, replace that button to link with the inquire button.
    – maxasela
    Commented Jun 19, 2019 at 7:33
  • I was able to use the answer you gave, That was a huge help. What I did was, Used the contact form code you mentioned in Github and used a remove cart plugin. And then in each product gave a link to inquiry page with item name and price, id. But this is a Temporary Solution. Because even when the user select more than one quantity of the product or a variation of the product inquiry page will display the same quantity or the variation which I added to the link,
    – maxasela
    Commented Jun 19, 2019 at 7:38
  • I edited my answer above with info how to remove the cart button from every product. If you remove the add to cart button, also the quantity input gets removed. Regarding variations ... I only used this for simple products. When variations are involved, you should use the variation ID and other variation data as URL attributes and not the general product data.
    – LWS-Mo
    Commented Jun 19, 2019 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.