php - saving and displaying embedded video in WooCommerce / WC Vendor Pro -


i have added custom text field woocommerce , displayed in frontend of wc vendor pro. vendors can add youtube or vimeo link embed movies.

however reason can't save , display in product page on front end.

the code have far in 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 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 ) );  } 

and display field in vendor section:

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

so vendors can enter field. saving nor displaying won't work. added following product page:

echo $youtubevideo_code = wp_oembed_get( get_field('video_url') ); // tried 1 well: echo get_post_meta( $post->id, 'video_url', true ); 

thanks appreciated!

assuming use acf use get_field, think miss second parameter $post_id, function need know post id of field want get.

echo $youtubevideo_code = wp_oembed_get( get_field('video_url') ); 

you must right this

global $post; // don't know script (in loop ? in function ?)   $youtubevideo_code = wp_oembed_get( get_post_meta($post->id, 'video_url', true )); // can get_field('video_url, $post->id);  echo $youtubevideo_code; 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -