Home > Back-end >  Looking for query to get meta_value
Looking for query to get meta_value

Time:12-19

So i'm using Wordpress, Woocommerce and the "Product Video for WooCommerce" plugin by Addify. The URL to a mp4 video is stored in the:

wp_postmeta table

In this table, the post_id matches the product. In the "meta_value" i can see the URL i've added.

No my question; I want to place a download button that downloads the video stored in this location. I've located the woocommerce hook where the button needs to come, but I can't figure out how to fetch the url from this meta_value.

My code skills are very basic so this is to complicated for me. Can anyone help me out on this?

This showed me that the URL is visible but surely not the end goal :-)

add_filter( 'woocommerce_share', 'custom_button', 20 );
function custom_button() {
$meta = get_post_meta(get_the_ID(), '', true);
print_r($meta); 

}
  //Here I want to add the button
print '<button>Download video</button>';

Thanks!

Picture from DB table

CodePudding user response:

'woocommerce_share' hook is an action, not filter.

Try this

add_action( 'woocommerce_share', 'custom_button', 20 );
function custom_button() {
    $download_url = get_post_meta(get_the_ID(), 'afpv_cus_featured_video_id', true);

    if ( empty( $download_url ) ) { // do not print anything if download_url doesn't exists
        return;
    }

    // print the download button
    printf( '<a href="%s"  target="_blank" download>%s</a>', 
        esc_url( $download_url ), 
        __( 'Download video', 'text-domain' ) // string can be translated, change text-domain by the theme domain or plugin domain
    );
}
  • Related