Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to programatically create a WooCommerce downloadable product?

Create a metabox for the admin editor in single product. I use a plugin instead of trying to add to child theme or functions.

//add a woocommerce metabox to the product editor
add_action( 'woocommerce_product_options_general_product_data', 'plugin_add_audio_meta_box' );

function plugin_add_audio_meta_box()
{ ....
 <tr>
        <td class="file_url">
            <input type="text" class="input_text"
            placeholder="<?php esc_attr_e( "http://", 'plugin' ); ?>"
            name="_plugin_two"
            value="<?php echo $plugin_fileurl; ?>" />
        </td>

       <td class="file_url_choose" width="1%">
            <a href="#" class="button upload_file_button"
            data-choose="<?php esc_attr_e( 'Choose file', 'plugin' ); ?>"
            data-update="<?php esc_attr_e( 'Insert file URL', 'plugin' ); ?>">
            <?php echo str_replace( ' ', '&nbsp;', __( 'Choose file', 'plugin' ) ); ?></a>
        </td>
        </tr>
.... }

function save_fields ...
update_post_meta( $post_id, ....

Then call the file wherever you need it on the front side:

<p><?php
            $attr = array(
                'src'      => strip_tags($plugin_fileurl),
                'loop'     => 'true',
                'autoplay' => '',
                'preload'  => 'none',
            );

            echo '<div class="audio-player" itemprop="audio">' . wp_audio_shortcode( $attr ) . ' </div>';

            /* echo do_shortcode(''.esc_url($plugin_fileurl).''); */
            ?></p>

Related Posts:

  1. WP/WooCommerce REST API cart/checkout/order [closed]
  2. WooCommerce conditional meta query
  3. Creating woocommerce product using WordPress REST API
  4. WooCommerce: Adding Order Item Meta Data That’s Hidden
  5. WP_Query with meta_query for children
  6. Woocommerce REST API allow normal users make an order
  7. How to update custom field in WooCommerce
  8. How to upload multiple image using wp_insert_post
  9. Expired session error (admin) when I try to make a call to WooCommerce api [closed]
  10. Set default value field meta_Value [closed]
  11. How can I get all the woocommerce api orders [closed]
  12. wc_get_products() not return the images details
  13. update_post_meta not work [closed]
  14. Woocommerce REST API – add filter to set maximum query per page for product brands [closed]
  15. Update Customer JWT Woocommerce
  16. Woocommerce, finding the ordinal number of a purchase for a certain product
  17. WooCommerce order refund get qty refunded
  18. WordPress SMS API integration without plugin error
  19. Absolute search against wordpress api
  20. WooCommerce Bookings Plugin Not Saving Order ID
  21. Conditionally run function based on custom meta value?
  22. Next/Previous Product with custom order by price & products inside the product category [closed]
  23. How to add custom checkboxes from loop to WooCommerce product variation options?
  24. WordPress Woocommerce REST API JSON Error
  25. Getting WordPress fatal error when hitting WooCommerce API
  26. woocommerce REST api on the website’s front-end
  27. How to save one API response to WooCommerce order meta data
  28. How can I get a get a list of customers from a list of email addresses?
  29. How to get WordPress to respond to a GET request at the end of a Woo product page
  30. How to save a Woocomerce metabox input as a metadata field
  31. Working with a json feed & trying to figure out how best to import
  32. Delete product image using WooCommerce API?
  33. Can’t update WooCommerce payment method title
  34. email address non required
  35. Update Custom Post Meta Even if Draft
  36. WordPress returning “XHR” even when access keys are used
  37. Users credentials and syncing from third party with WooCommerce
  38. Manual Woocommerce Complete order Emails
  39. WooCommerce REST API endpoints don’t exist
  40. Updating order meta to have a meta entry from an item in the order
  41. Fetch products with filter by similar categories at same time
  42. Woocommerce API REST search by multiple keywords
  43. Create WordPress account on different domain when WooCommerce order completed
  44. acf_form() – “On Update” action [closed]
  45. Auto generating API keys using the Application Authentication Endpoint [closed]
  46. Woocommerce – Add a product to cart programmatically via JS or PHP [closed]
  47. ( Woocommerce) How to get the user belonging to an order? [closed]
  48. Get the product list of a given Category ID
  49. List of JS events in the WooCommerce frontend
  50. get woocommerce My account page link
  51. WooCommerce: How to edit the get_price_html
  52. Get woocommerce product price by id [closed]
  53. Product categories don’t appear as option to build menu
  54. WooCommerce Variable Product Price not showing on single product page
  55. How to override WooCommerce template files?
  56. Woocommerce add extra field to variation product
  57. Getting the gallery images from products in woocommerce?
  58. How to get current product category ID in product archive page
  59. Get url of product’s images (woocommerce)
  60. WooCommerce prices location in DB
  61. What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
  62. Best way to programmatically remove a category/term from a post
  63. Order by rating not works in wp_query
  64. Woocommerce: How to remove page-title at the home/shop page but not category pages
  65. Woocommerce show cross sells on singe product page [closed]
  66. How to add a new endpoint in woocommerce
  67. Are there any hook or filter when refund is done through admin -woocommerce
  68. How to check if is in cart page? [closed]
  69. Display single product attribute value on Shop page (Woocommerce)
  70. how to use wc_create_order with subscription product
  71. WooCommerce: Webhook disabled on its own
  72. What is the code to get the download link for a product in WooCommerce?
  73. Share users and WooCommerce memberships between two installations
  74. Slow Loading Attribute Select – WooCommerce Backend
  75. WooCommerce: Can’t use wc_get_products for custom REST API endpoints
  76. How to change or add Woocommerce thank you page URL key content?
  77. How can I define a custom template for woocommerce [products] shortcode? [closed]
  78. How to remove an action within a class with extends
  79. single-product.php template not working for single products [closed]
  80. Insert variations via woocommerce api [closed]
  81. WooCommerce get physical store address
  82. Is it possible to add custom fields to a WooCommerce attribute term? [closed]
  83. wc_get_template_part( ‘content’, ‘product’ ) | Where is this file located?
  84. how to get woocommerce product attribute slug
  85. Correct function to get the user’s latest Woocommerce Subscription?
  86. Move payment options at checkout in WooCommerce [closed]
  87. add_filter to modify woocommerce_cart_item_name hyperlink
  88. Where do the cart details are stored in database?
  89. How to display product price of the product in loop
  90. Trying to get custom post meta through Jetpack JSON API [closed]
  91. How to disable Woocommerce password recovery and use the default WordPress password reset page?
  92. Display order items names in WooCommerce admin orders list [closed]
  93. Is it safe to delete from db orphaned posts i.e. whose post_parent no longer exists?
  94. Add custom variable to cart content [closed]
  95. Get product details by url key in WordPress woocommerce
  96. Get product link
  97. WooCommerce – Hook after Loading Variation in Admin Edit page?
  98. How to delete woo commerce order pragmatically? [closed]
  99. WooCommerce changes lost password reset link
  100. Process checkout using WC REST API
Categories woocommerce-offtopic Tags api, post-meta, woocommerce-offtopic
How to update user role totals
Advanced Custom Fields deleting some code and adding code for a slider

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress