M
M
Muxammadislom Eshonqulov2021-08-04 10:34:55
WordPress
Muxammadislom Eshonqulov, 2021-08-04 10:34:55

Save custom WooComerce field value during new product creation via Dokan?

Good time.
Created a new field for the product woocomerce.
functions.php

function art_added_tabs_panel() {
  $product = wc_get_product();
    global $product, $post;
  ?>
  <div id="special_panel_product_data" class="panel woocommerce_options_panel">
    <div class="options_group">
      <?php
            woocommerce_wp_text_input( array(
                'id'                => '_text_field_ISBN',
                'label'             => __( 'ISBN', 'woocommerce' ),
                'placeholder'       => 'Текстовое поле',
                'desc_tip'          => 'true',
                'custom_attributes' => array( 'required' => 'required' ),
                'description'       => __( 'ISBN — это международный номер бумажной или электронной книги.', 'woocommerce' ),
            ) );
       
      ?>

    </div>
  </div>
  <?php
}
add_action( 'woocommerce_product_data_panels', 'art_added_tabs_panel' );
add_action( 'woocommerce_process_product_meta', 'art_woo_custom_fields_save', 10 );
function art_woo_custom_fields_save( $post_id ) {
  // Сохранение текстового поля
  $woocommerce_text_field = $_POST['_text_field_ISBN'];
  if ( !empty($woocommerce_text_field) ) {
  update_post_meta( $post_id, '_text_field_ISBN', esc_attr( $woocommerce_text_field ));
//   $product->save();
  }
}
add_action( 'woocommerce_shop_loop_item_title',function(){
    $product = wc_get_product();
    echo get_post_meta($product->get_id(),'_text_field_ISBN', true);
},15);

I'm trying to make the seller fill in this field when adding a new product.
In the new-product.php file, in the form tag, a new input but cannot be saved to the costume field.
Searched the Internet. It works but the field value is not displayed in woocomerce products.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question