【问题标题】:Looking for query to get meta_value寻找查询以获取 meta_value
【发布时间】:2022-01-20 18:02:26
【问题描述】:

所以我正在使用 Wordpress、Woocommerce 和 Addify 的“WooCommerce 产品视频”插件。 mp4 视频的 URL 存储在:

wp_postmeta table

在此表中,post_id 与产品匹配。 在“meta_value”中,我可以看到我添加的 URL。

没有我的问题; 我想放置一个下载按钮,用于下载存储在此位置的视频。 我已经找到了按钮需要到达的 woocommerce 钩子,但我不知道如何从这个 meta_value 中获取 url。

我的代码技能非常基础,所以这对我来说太复杂了。 谁能帮我解决这个问题?

这表明 URL 是可见的,但肯定不是最终目标 :-)

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

谢谢!

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    'woocommerce_share' 钩子是一个动作,而不是过滤器。

    试试这个

    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
        );
    }
    

    【讨论】:

    • 了不起的乔!这正是我想要的!非常感谢您这么快得到正确的答案!非常感谢!
    • 不客气,能把我的答案设为正确答案吗?
    猜你喜欢
    • 2021-07-02
    • 1970-01-01
    • 2011-03-04
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2018-02-16
    • 1970-01-01
    相关资源
    最近更新 更多