api – How to programatically create a WooCommerce downloadable product?

Create metabox for admin editor in single product. I’d rather use a plugin than try to add in a 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 up front wherever you need it:

<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>

Leave a Comment