PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 8, 2022

[FIXED] Looking for query to get meta_value

 January 08, 2022     woocommerce, wordpress     No comments   

Issue

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!

enter image description here


Solution

'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" class="button" 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
    );
}


Answered By - Jo Kolov
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing