所以我使用WordPress的,Woocommerce和“產品視頻為WooCommerce”通過插件Addify。mp4 視頻的 URL 存盤在:
wp_postmeta 表
在此表中,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>';
謝謝!
圖片來自資料庫表
uj5u.com熱心網友回復:
'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" 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
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/385209.html
標籤:WordPress的 网址 视频 求购
上一篇:使用wp_insert_post插入wordpress帖子并附上特色圖片
下一篇:如何隱藏帖子下的類別選項卡?
