WP SITES

3089 Coded Tutorials & 296 Plugins

Add Download Button For Virtual Products For Paying Customers

This code adds a download button linked to the virtual downloable product, if it exists, on the single product page. The code :

  • Checks if the customer is logged in, if not, the button will not display.
  • Checks if the customer has bought the product and the order has completed, otherwise the button does no display.
  • Checks the URL for the link to the download has been added as a download file to the single product otherwise, the button does not display.
  • Works with Gutenberg block and non block classic editor themes.
  • Doesn’t affect the default add to cart button unless you add the 2nd snippet which replaces the add to cart button with the download button for existing customers only.

The 1st snippet adds the download button inline with the add to cart button.

Hide Add To Cart

2nd snippet. The download folder also includes another snippet which hides the add to cart button if the customer order has completed payment and its a downloadable virtual product with file name and file added.

This only works when logged in so the default add to cart button displays when logged out or when the logged in user hasn’t completed purchase.

Installation

Copy and paste the PHP code to the end of your child themes functions file or custom code snippets plugin.

Leave a Reply

New Plugins