Home / Admin / WhatsApp Button to WooCommerce Single Product Pages
Duplicate Snippet

Embed Snippet on Your Site

WhatsApp Button to WooCommerce Single Product Pages

Display a WhatsApp button on WooCommerce single product pages. You can customize color and shape of the WhatsApp icon as per your website theme. It's easy for customers to call from the product.
Remember to replace 'WhatsApp_icon.webp' with the URL of your WhatsApp button image and 'https://wa.me/00112222333' with your actual WhatsApp number.

Code Preview
php
<?php
/**
 * Enqueue script and styles for child theme
 */
function woodmart_child_enqueue_styles() {
	wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'woodmart-style' ), woodmart_get_theme_info( 'Version' ) );
}
add_action( 'wp_enqueue_scripts', 'woodmart_child_enqueue_styles', 10010 );
define('ALLOW_UNFILTERED_UPLOADS', true);
function add_whatsapp_buttonlux() {
    ?>
    <style>
        .whatsapp-buttonlux {
            display: none; /* Initially hide the button */
            padding: 8px; /* Adjust padding for a smaller button */
            border-radius: 10px; 
            border: 1px solid #939393;
            text-decoration: none;
            font-size: 16px;
            white-space: nowrap;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); 
            transition: background-color 0.3s ease-in-out; /* Smooth color transition */
            width: 50%; 
            text-align: center;
        }
        .whatsapp-buttonlux:hover {
            background-color: #c3935b !important; /* Darker color on hover */
        }
        .whatsapp-buttonlux img {
            width: 30px; 
            height: 30px; 
            margin-right: 5px;
            vertical-align: middle;
        }
        @media only screen and (max-width: 767px) {
            .whatsapp-buttonlux {
                width: 60%; 
            }
            .whatsapp-buttonlux img {
                width: 30px; 
                height: 30px; 
            }
        }
    </style>
    <div class="whatsapp-buttonlux">
		// Please enter your WhatsApp number
        <a href="https://wa.me/00112222333" target="_blank" rel="noopener">
		// Please replace WhatsApp button image with URL
            <img src="WhatsApp_icon.webp" alt="WhatsApp Call" />
            Call Us for Price
        </a>
    </div>
    <script>
        jQuery(document).ready(function ($) {
            // Show the WhatsApp button after the page has loaded
            $('.whatsapp-buttonlux').show().insertAfter('.single-product-page .wd-social-icons');
        });
    </script>
    <?php
}
add_action('woocommerce_before_single_product', 'add_whatsapp_buttonlux', 10);

Comments

Add a Comment