PurpleTurtleCreative / website

Official WordPress website of Purple Turtle Creative.
https://purpleturtlecreative.com/
1 stars 0 forks source link

Install WooCommerce for ptc-resources-server fulfillment #16

Open MichelleBlanchette opened 3 weeks ago

MichelleBlanchette commented 3 weeks ago

We can sell resources from ptc-resources-server by using WooCommerce + Stripe payment gateway + downloadable product types for free. I realized we don't need to bother paying for WooCommerce Subscriptions and people can simply be prompted to manually purchase the product again in the meantime, if we even want to enforce that... One step at a time... 🫠

See the user guide: https://woocommerce.com/document/digital-downloadable-product-handling/

We can programmatically update the downloadable file associated with each product during the plugin release deployment (via cURL request to a custom REST API endpoint, for example) like so:

// Written by ChatGPT. Not reviewed for accuracy, but illustrates the basic idea.
function update_downloadable_file_path($product_id, $new_file_path) {
    // Retrieve the existing downloadable files (it can be an array of multiple files)
    $downloadable_files = get_post_meta($product_id, '_downloadable_files', true);

    // Check if there are existing downloadable files
    if (!empty($downloadable_files)) {
        // Assuming there's only one downloadable file and you want to update it
        foreach ($downloadable_files as $download_id => $file) {
            // Update the file path with the new file path
            $downloadable_files[$download_id]['file'] = $new_file_path;
        }
    } else {
        // If no existing files, you can add a new downloadable file entry
        $download_id = md5(uniqid());
        $downloadable_files = array(
            $download_id => array(
                'name' => 'Your File Name', // Adjust the name as needed
                'file' => $new_file_path,
            )
        );
    }

    // Update the downloadable files meta for the product
    update_post_meta($product_id, '_downloadable_files', $downloadable_files);
}
MichelleBlanchette commented 3 weeks ago

Relates to https://github.com/PurpleTurtleCreative/ptc-resources-server/issues/13