Php 在WooCommerce/WC Vendor Pro中保存和显示嵌入式视频
我为woocommerce添加了一个自定义文本字段,并将其显示在Php 在WooCommerce/WC Vendor Pro中保存和显示嵌入式视频,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我为woocommerce添加了一个自定义文本字段,并将其显示在WC Vendor pro的前端。因此,供应商可以添加youtube或vimeo链接来嵌入他们的电影 但是由于某些原因,我无法将其保存并显示在前端的产品页面中 到目前为止,我在functions.php中的代码如下: // Display Fields add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fie
WC Vendor pro
的前端。因此,供应商可以添加youtube或vimeo链接来嵌入他们的电影
但是由于某些原因,我无法将其保存并显示在前端的产品页面中
到目前为止,我在functions.php
中的代码如下:
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
woocommerce_wp_text_input(
array(
'id' => 'video_url',
'label' => __( 'Your product video link (youtube/vimeo)', 'woocommerce' ),
'placeholder' => 'https://',
'desc_tip' => 'true',
'description' => __( 'Copy the Youtube or Vimeo link here', 'woocommerce' )
)
);
echo '</div>';
}
function woo_add_custom_general_fields_save( $post_id ){
// Text Field
$woocommerce_text_field = $_POST['video_url'];
if( !empty( $woocommerce_text_field ) )
update_post_meta( $post_id, 'video_url', esc_attr( $woocommerce_text_field ) );
}
<div class="all-100">
<!-- Media uploader -->
<div class="wcv-product-media">
<?php BuddyBoss_BM_Templates::product_media_uploader( $object_id ); ?>
<?php woo_add_custom_general_fields( $object_id ); ?>
</div>
</div>
echo $youtubevideo_code = wp_oembed_get( get_field('video_url') );
// tried this one as well:
echo get_post_meta( $post->ID, 'video_url', true );
感谢您的帮助,我们将不胜感激 假设您使用acf来使用
get\u field
,我认为您错过了第二个参数$post\u id,函数需要知道您想要获取的字段的post id
echo $youtubevideo_code = wp_oembed_get( get_field('video_url') );
你必须这样纠正它
global $post; // I don't know where is your script (in the loop ? in a function ?)
$youtubevideo_code = wp_oembed_get( get_post_meta($post->ID, 'video_url', true )); // can be get_field('video_url, $post->ID);
echo $youtubevideo_code;
假设您使用acf来使用
get\u field
,我认为您错过了第二个参数$post\u id,函数需要知道您想要获取的字段的post id
echo $youtubevideo_code = wp_oembed_get( get_field('video_url') );
你必须这样纠正它
global $post; // I don't know where is your script (in the loop ? in a function ?)
$youtubevideo_code = wp_oembed_get( get_post_meta($post->ID, 'video_url', true )); // can be get_field('video_url, $post->ID);
echo $youtubevideo_code;
谢谢你的回复。确实试图添加它,但没有结果。我认为链接也没有正确保存,保存后不会再次显示。还有其他想法吗?谢谢你的回复。确实试图添加它,但没有结果。我认为链接也没有正确保存,保存后不会再次显示。还有其他想法吗?