0

I wanted to have custom text input fields with the attribute name already defined for the products. Since this is not natively possible in Woocommerce I have added a custom text input field for one of my attributes “Forgaffel”. This information is to be shown under the “Additional information” tab on the product page a long with the other product attributes.

I have used the following code for this:

* Add custom text field
**/
function my_woo_custom_price_field() {

  $field = array(
    'id' => 'christmas_price',
    'label' => __( 'Forgaffel', 'textdomain' ),
    'data_type' => 'text' //Let WooCommerce formats our field as price field
  );

  woocommerce_wp_text_input( $field );
}
/**
* Save custom text field
**/
add_action( 'woocommerce_process_product_meta', 'save_custom_field' );
function save_custom_field( $post_id ) {

  $custom_field_value = isset( $_POST['my_custom_input'] ) ? $_POST['my_custom_input'] : '';

  $product = wc_get_product( $post_id );
  $product->update_meta_data( 'my_custom_input', $custom_field_value );
  $product->save();
}

However, how do I retrieve this information and display it under “Additional information” tab? I am using the WP Ocean theme.

And is there an easier way to add custom text input fields (with the attribute name predefined) for the information under “Additional information” tab?

Thanks in advance!

1 Answer 1

0

I managed to achieve this using ACF and editing the "product-attributes.php" file in the woocommerce plugin.

1
  • Hi, i am trying to achieve same, can you explain a bit how did you manage that? thanks
    – MMK
    Commented Sep 8, 2020 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.