Create a custom inside a product Admin Page to create a editor field

// Add Feature overview meta field to product admin page

function add_feature_description_meta_field() {

  global $post;

  // Get the existing value

  $feature_description = get_post_meta($post->ID, ‘feature_description’, true);

  // Output the field

  echo ‘<div class=”options_group”>’;

  echo ‘<p class=”form-field”>

      <bold><label for=”sub_description”>’ . esc_html__(‘Feature Description’, ‘woocommerce’) . ‘</label></bold>

    </p>’;

  wp_editor(

    $feature_description,

    ‘feature_description’,

    array(

      ‘textarea_name’ => ‘feature_description’,

      ‘label’    => __(‘Sub Description’, ‘woo commerce’),

      ‘textarea_rows’ => 5, // Set the number of rows in the editor

      ‘wpautop’    => true, // Enable automatic paragraphs

    )

  );

  echo ‘</div>’;

}

add_action(‘woocommerce_product_options_general_product_data’, ‘add_feature_description_meta_field’);

// Save key features meta field data

function save_feature_description_field($post_id) {

  $feature_description = isset($_POST[‘feature_description’]) ? wp_kses_post($_POST[‘feature_description’]) : ”;

  update_post_meta($post_id, ‘feature_description’, $feature_description);

}

add_action(‘woocommerce_process_product_meta’, ‘save_feature_description_field’);

// Add key features meta field to REST API response

function add_feature_description_to_api($response, $post, $request) {

  $feature_description = get_post_meta($post->ID, ‘feature_description’, true);

  if ($feature_description) {

    $response->data[‘meta_data’][] = array(

      ‘key’  => ‘feature_description’,

      ‘value’ => $feature_description,

    );

  }

  return $response;

}

add_filter(‘woocommerce_rest_prepare_product_object’, ‘add_feature_description_to_api’, 10, 3);

This field creates an editor field which is available in the woocommerce product data section as well as in the metadata section of the product REST API

Leave a comment

Your email address will not be published. Required fields are marked *