• Resolved teodorradu22

    (@teodorradu22)


    Hello, everyone!

    I’m currently building a woocommerce website for some digital products, like 3D models that i want to sell and i want to implement a function that when a customer is on page of the product that they already bought, it should display Download button instead of Add to cart button. Do you guys have any idea how I could do that?

    Thanks in advance!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @teodorradu22

    To implement the functionality you’ve described, where a “Download” button is displayed on a product page instead of the “Add to Cart” button for products that a customer has already purchased, you can add the following code snippet to your child theme’sfunctions.php file:

    function wc_custom_replace_add_to_cart_button( $button, $product ) {
    if ( $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && $product->is_downloadable() ) {
    $current_user = wp_get_current_user();
    if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->get_id() ) ) {
    $button_text = __("Download", "woocommerce");
    $button = '' . $button_text . '';
    }
    }
    return $button;
    }
    add_filter( 'woocommerce_loop_add_to_cart_link', 'wc_custom_replace_add_to_cart_button', 10, 2 );

    This code checks if the current user has already purchased the product and if the product is a downloadable digital product. If both conditions are met, it replaces the “Add to Cart” button with a “Download” button.

    I hope this help, Thanks!

    Thread Starter teodorradu22

    (@teodorradu22)

    Hello Shameem!

    Tried it, doesn’t work.

    The code itself does not replace the “Add to cart” button’s functionality neither the name.

    Hi @teodorradu22

    Thanks for reaching out!

    I understand that you are looking for the functionality of displaying a Download button instead of an Add to Cart button for customers who have already purchased a specific digital product on your site, correct?

    I did some research and found these articles could be a good starting point:

    Meanwhile, this is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Swap add to cart to Download Button when logged in’ is closed to new replies.