admin管理员组文章数量:1419702
I have a plugin that adds videos in place of the featured image of Woocoemerce products. The plugin just adds the video URL and saves it within the product. I would like to provide the saved URL via Metadata, so that I can edit each product by exporting to a .CSV (Woocommerce export functionality) table.
I was able to find in the plugin the moment the URL was saved in the product. But I don't know how to transform this information as Woocomerce Metadata.
public function woofv_save_video_box( $post_id ) {
if ( ! isset( $_POST['woofv_video_box_nonce'] ) ) {
return $post_id;
}
$nonce = $_POST['woofv_video_box_nonce'];
if ( ! wp_verify_nonce( $nonce, 'woofv_video_box' ) ) {
return $post_id;
}
if ( 'product' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return $post_id;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
}
$woofv_data = array_map('sanitize_text_field', $_POST['woofv_video_embed'] );
update_post_meta( $post_id, '_woofv_video_embed', $woofv_data );
}
The plugin saves the video link in the variable $video_url
. And that's exactly this variable I'd like to add as Woocomerce metadata. How would it be possible to make this work?
Plugin page if necessary: Wordpress plugin page - Woo featured video
I have a plugin that adds videos in place of the featured image of Woocoemerce products. The plugin just adds the video URL and saves it within the product. I would like to provide the saved URL via Metadata, so that I can edit each product by exporting to a .CSV (Woocommerce export functionality) table.
I was able to find in the plugin the moment the URL was saved in the product. But I don't know how to transform this information as Woocomerce Metadata.
public function woofv_save_video_box( $post_id ) {
if ( ! isset( $_POST['woofv_video_box_nonce'] ) ) {
return $post_id;
}
$nonce = $_POST['woofv_video_box_nonce'];
if ( ! wp_verify_nonce( $nonce, 'woofv_video_box' ) ) {
return $post_id;
}
if ( 'product' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return $post_id;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
}
$woofv_data = array_map('sanitize_text_field', $_POST['woofv_video_embed'] );
update_post_meta( $post_id, '_woofv_video_embed', $woofv_data );
}
The plugin saves the video link in the variable $video_url
. And that's exactly this variable I'd like to add as Woocomerce metadata. How would it be possible to make this work?
Plugin page if necessary: Wordpress plugin page - Woo featured video
Share Improve this question edited Aug 2, 2019 at 22:02 Syd McArdle 437 bronze badges asked Aug 2, 2019 at 19:55 LucasLucas 12 bronze badges1 Answer
Reset to default 0Lucas!
Typically when a plugin like this is used to save data to a specific product (images, notes, or in your case, video) that "save" is storing that information in the product's meta for use, so it should already be there for you. Judging by the code snipped provided, this is happening in..:
update_post_meta( $post_id, '_woofv_video_embed', $woofv_data );
With the video link being stored in the variable "$woofv_data" in this specific function, and "_woofv_video_embed" being the meta key you would use to access this value later.
If you would like to see what is going on within your product's meta, there are plugins like JSM's Show Post Meta that will actually display a list of all your product / other post type's meta keys and values below. Having something like this when developing can be pretty handy as it takes out a lot of the guesswork when trying to assess what information is or isn't being stored, and where it's stored at.
本文标签: woocommerce offtopicHow to save a Woocomerce metabox input as a metadata field
版权声明:本文标题:woocommerce offtopic - How to save a Woocomerce metabox input as a metadata field 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745274209a2651081.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论