woocommerce offtopic - How to save a Woocomerce metabox input as a metadata field

I have a plugin that adds videos in place of the featured image of Woocoemerce products. The plugin just adds the 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

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Lucas!

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745274210a4619936.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信