WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] identify if particular product has been purchased (9 posts)

  1. jimlongo
    Member
    Posted 1 year ago #

    I have a main product that is required to be purchased (or submit proof of purchase) before buying other products.

    I have the "proof of purchase" requirement satisfied by submitting a code from your purchase receipt that stores a session variable $_SESSION['purchased'] = true. Then if this variable is true you can proceed to the all products page.

    If they don't have a proof of purchase, How would I set this variable based on the (addition to the cart) of Product XYZ? Or is there a better way you can think of to accomplish this functionality?

    I do realize that people may remove it from the cart after having placed it there, but the client understands that possibility.

    http://wordpress.org/extend/plugins/woocommerce/

  2. jimlongo
    Member
    Posted 1 year ago #

    Here's my thinking . . .
    in my plugin I put the following action hook

    add_action( 'woocommerce_cart_contents'  , 'nfp_purchased_photo');
    function nfp_purchased_photo() {
        if( $product_id == '1450' ){
            $_SESSION['purchased']= 'true';
        }
        else{
            continue;
        }
    }

    this is trying to hook into woo commerce/cart.php which has this
    do_action('woocommerce_cart_contents' );

    Of course that is not doing what I want.
    Any other hooks that you would think more appropriate?

  3. varktech.com
    Member
    Posted 1 year ago #

    Hi,
    So product 1450 must either be in the cart, or the 'proof of purchase' function must have been satisfied, to either:
    (1) access the main product catalog
    or
    (2) checkout
    ??

  4. jimlongo
    Member
    Posted 1 year ago #

    It must be in the cart to access the main product catalog.

    If $_SESSION['purchased'] = 'true' then when you click the link it redirects to the main catalog, otherwise it redirects to the single product i want you to buy.

  5. varktech.com
    Member
    Posted 1 year ago #

    why not apply the requirement at checkout time - easier to program, I think... that way they can see and use the catalog to add any product to cart, but can't check out until 'purchased' is satisfied?

  6. jimlongo
    Member
    Posted 1 year ago #

    I suppose that's a possibility. It depends on how user friendly the whole process is, I hate to make things difficult for customers.

    How would you accomplish that?

    Thanks.

  7. varktech.com
    Member
    Posted 1 year ago #

    One approach would be to:
    (1)grab a copy of my plugin http://wordpress.org/plugins/minimum-purchase-for-woocommerce/
    (2) hack the core/vtmin-apply-rules.php file, function vtmin_minimum_purchase_check(), to do just what you want. Remove all of the function's code, and then create new code to verify 'purchased' or loop through the cart class and verify if 1450 purchased. If not, add your message to the cart class with the following: $vtmin_cart->error_messages[] = array ('msg_from_this_rule_id' => $rule_id_list, 'msg_from_this_rule_occurrence' => '', 'msg_text' => $message );
    (3) the hacked plugin will do the rest, injecting the message in a nice format at the top of the cart.
    (4) create a 'minimum purchase rule' (which in this case will do your function only) to cover all user roles, to activate the works.

    and Bob's your uncle, Fanny's your aunt.

    Vark

  8. jimlongo
    Member
    Posted 1 year ago #

    I've been looking at your plug-in page and that's pretty interesting.

    So in fact there are 4 products (1450, 1451, 1452, 1453) that could qualify you to checkout OR the proof of purchase code.

    I'll give it a whirl and see where it goes. I wouldn't mind paying for or donating to such a thing. Do I need the Min Pro version to apply to all the contents of the cart?

  9. jimlongo
    Member
    Posted 1 year ago #

    @varktech.com
    Your suggestion worked great! And I think it is both easier for the customer to understand and better from a sales perspective to let them see all the products as an incentive.

    Thanks for the advice.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic