Snippet to Unlock The Power of Personalization in Your WooCommerce Store

According to Harvard Business Review, Acquiring a new customer can cost 5 times more than retaining an existing customer. 

We could apply this crucial knowledge to our advantage by adding an additional personality to our eCommerce store. It would be truly incredible if we could display a personalized message once a consumer makes a purchase from our online store and we can identify when the customer visits again. It would enhance the whole experience and give your WooCommerce business a personal touch.

Message we want to show

We will be using the woocommerce_single_product_summary hook to display the function. It will help us display our function output just below the price of WooCommerce single product page.

PHP Snippet

<?php

// Display purchased information on single product page
add_action('woocommerce_single_product_summary', 'display_repeat_purchase_info', 15);
function display_repeat_purchase_info() {
    global $product;

    // Check if the user is logged in
    if (is_user_logged_in()) {
        $current_user = wp_get_current_user();

        // Check if the user has purchased this product before
        if (wc_customer_bought_product($current_user->user_email, $current_user->ID, $product->get_id())) {
            $purchase_date = wc_customer_bought_product($current_user->user_email, $current_user->ID, $product->get_id(), true);

            $formatted_date = date_i18n(get_option('date_format'), strtotime($purchase_date));

            ?>

            <p class="woo-personalize">
            	You have excellent taste, <?php echo $current_user->display_name;?>. You made a wise decision when you bought this item on <?php echo esc_html($formatted_date);?>. Want to experience that happiness again?
            </p>
            <?php
        }
    }
}

CSS Snippet

p.woo-personalize {
    background-color: #EDE7F6;
    padding: 1.4rem;
    border-radius: 6px;
    border: 1px solid #d2c8e1;
}

Where to add PHP code?

PHP code snippets and CSS code should be at the bottom of your child theme’s style.css and functions.php files, respectively. 

Although this is just one simple instance of store customization, there are other sophisticated and efficient ways to make your store more vibrant. Numerous WooCommerce plugins are available to help you give your store a more distinctive touch and increase the level of seamless automation.

Leave a Comment

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

Scroll to Top