"Ask a Question About This Product" Link
Adds a link under the Add to Cart button that opens an email to your shop with the product name and link already filled in, an easy way to capture pre-sale questions.
Opens WPIDE on
Code
$wpide_question_email = '[email protected]'; // Address that receives questions.
add_action( 'woocommerce_after_add_to_cart_form', function () use ( $wpide_question_email ) {
global $product;
if ( ! $product instanceof WC_Product || ! is_email( $wpide_question_email ) ) {
return;
}
$subject = rawurlencode( 'Question about ' . $product->get_name() );
$body = rawurlencode( "Hi,\n\nI have a question about " . $product->get_name() . ' (' . $product->get_permalink() . "):\n\n" );
printf(
'<p class="wpide-product-question"><a href="mailto:%1$s?subject=%2$s&body=%3$s">%4$s</a></p>',
esc_attr( $wpide_question_email ),
esc_attr( $subject ),
esc_attr( $body ),
esc_html( 'Have a question about this product?' )
);
} );
Notes
Set the address in $wpide_question_email; the visitor's own email app sends the message, so no form data passes through your site.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.