1. HOT Be a Pro member & access all our premium Divi extensions, including the popular Divi Block - Pro Version & many more.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Layout Packs - Beautifully crafted Divi layout packs for you to kick start your Divi sites.
View All Pro Layout Packs
BEST Divi Block - An online drag & drop tool to easily mix & match 456+ premade blocks (light / dark version), including custom header, fullscreen / slide in mobile menu, mega menu, custom footer, page design blocks, before / after image slider, promo bar, floating button, logo carousel, content toggle, slide in bar, etc.
Learn MoreTry Free Version

Solved Divi Conditions - Show if Item(s) in cart have previously been purchased

Discussion in 'Free Divi Community Forum' started by lesliec, Aug 5, 2022.

  1. lesliec

    lesliec New Member

    I sell downloadable products. I want to be able to tell my customer that they already own a specific product if they are viewing it or add it to their cart, or even on the cart page.

    I don't see a way to do this with the conditions option. Am I missing something there?

    Is there a different way to do this?

    Thanks,
    Leslie
     
    1. AD With 40+ Divi premium modules and extensions to choose from. Take Divi to the next level:Learn More
  2. lesliec

    lesliec New Member

    Well, I solved this myself by adding a few functions and a shortcode. Here they are for anyone who wants to do the same thing.

    I used 'pp' to stand for Prior Purchase

    The following shows up on the cart and checkout pages respectively.

    PHP:
    // Display a custom text under cart item name in cart page
    add_filter'woocommerce_cart_item_name''lb_cart_pp_name'10);
    function 
    lb_cart_pp_name$item_name$cart_item$cart_item_key ) {
        
    // Here below define your shipping class slug
        
    if (wc_customer_bought_product''get_current_user_id(), $cart_item['product_id'] )){
            
    $item_name .= '<div class="lb-cart-pp">You own one of these already!</div>';
        }
        return 
    $item_name;
    }
    // Display a custom text under cart item name in checkout
    add_filter'woocommerce_checkout_cart_item_quantity''lb_checkout_pp_qty'10);
    function 
    lb_checkout_pp_qty$item_qty$cart_item$cart_item_key ) {
        
    // Here below define your shipping class slug
        
    if (wc_customer_bought_product''get_current_user_id(), $cart_item['product_id'] )){
            
    $item_qty .= '<div class="lb-checkout-pp">Are you sure? You already purchased one of these!</div>';
        }
        return 
    $item_qty;
    }
    And this is a shortcode that I could add anywhere I want.
    PHP:
    add_shortcode'lb-priorpurchase''lunabug_prior_purchase' );
    //add_filter( 'woocommerce_cart_item_name', 'lunabug_prior_purchase', 10, 3 );

    function lunabug_prior_purchase() {
        global 
    $product;
        
    $fname get_user_metaget_current_user_id(), 'first_name'true );

        if ( ! 
    is_user_logged_in() ) return;
        if ( 
    wc_customer_bought_product''get_current_user_id(), $product->get_id() ) ) {
            return 
    '<div class="lb-priorpurchase pplus">' $fname ', you already own this, buy again?</div>';
        }
    }
    I hope this helps.