Product Enquiry for WooCommerce Shortcode

Below, you’ll find a detailed guide on how to add the Product Enquiry for WooCommerce Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Product Enquiry for WooCommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Product Enquiry for WooCommerce Plugin and the shortcodes it provides:

✩✩✩✩✩ () Active Installs: + Tested with: PHP Version:
Included Shortcodes:

Product Enquiry for WooCommerce [gmwqp_enquiry_single_product] Shortcode

The gm-woocommerce-quote-popup plugin shortcode, ‘gmwqp_enquiry_single_product’, enables users to make product inquiries directly. The code checks if a product ID is set, fetches the product, and verifies if it’s excluded from inquiries. If not, it displays an ‘Inquiry!’ button.

Shortcode: [gmwqp_enquiry_single_product]

Parameters

Here is a list of all possible gmwqp_enquiry_single_product shortcode parameters and attributes:

  • id – Specifies the unique identifier of the product

Examples and Usage

Basic example – The shortcode displays an enquiry button for a single product in WooCommerce. The product is identified by its ID, which is passed as an attribute to the shortcode.

[gmwqp_enquiry_single_product id=25 /]

Advanced examples

The shortcode can be used without passing any ID. In this case, it will automatically fetch the ID of the current product in the loop and display the enquiry button for it.

[gmwqp_enquiry_single_product /]

If you want to use the shortcode inside a PHP file, you can use the do_shortcode function. This is especially useful when you want to add the enquiry button in a custom location in your theme files.

Remember, the ID attribute should be replaced with the actual ID of the product for which you want to display the enquiry button.

PHP Function Code

In case you have difficulties debugging what causing issues with [gmwqp_enquiry_single_product] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('gmwqp_enquiry_single_product', array( $this, 'gmwqp_enquiry_single_product_shortcode' ));

Shortcode PHP function:

function gmwqp_enquiry_single_product_shortcode($atts){
		ob_start();
		global $post;
		if (isset($atts['id']) && $atts['id']!='') {
			$product_id = $atts['id'];
			$product = wc_get_product( $product_id );
		}else{
			$product_id = $post->ID;
			$product = wc_get_product( $product_id );
		}
		if(!empty($product)){
			if($this->gmwqp_is_exclude($product->get_id())==true){
			return;
			}
			
			if (get_option('gmwqp_button_label')!='') {
					$gmwqp_button_label = get_option('gmwqp_button_label');
			}else{
				$gmwqp_button_label = __('Inquiry!', 'gmwqp' );
			}
			
			?>
			<div class="gmwqp_inquirybtn_loop">
				<a href="#" class="button gmwqp_inq " title="<?php echo $product->get_name(); ?>" attr_id="<?php echo $product->get_id();?>"><?php echo $gmwqp_button_label;?></a>
			</div>
			
			<?php
		}
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}

Code file location:

gm-woocommerce-quote-popup/gm-woocommerce-quote-popup/includes/GMWQP_Frontend.php

Conclusion

Now that you’ve learned how to embed the Product Enquiry for WooCommerce Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *