Need help with displaying text field on woocommerce product category page
Support › General › Need help with displaying text field on woocommerce product category pageResolved
- This topic has 3 replies, 2 voices, and was last updated 5 years, 2 months ago by
Long Nguyen.
-
AuthorPosts
-
September 17, 2020 at 10:10 PM #21921
[email protected]
ParticipantHi there,
I am using the Metabox builder to create Metaboxes.
I would like to add a textarea field to the woocommerce product_category taxonomy. The theme that I'm using is Astra.
I have added this code to my functions.php file:
//custom Metabox test JP add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' ); function prefix_register_meta_boxes( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'title' => esc_html__( 'Product categorie text', 'text-domain' ), 'id' => 'product-categorie-text', 'fields' => [ [ 'id' => $prefix . 'textarea_1jtphdq0vy', 'type' => 'textarea', 'name' => esc_html__( 'Textarea Field', 'text-domain' ), ], ], 'taxonomies' => ['product_cat'], ]; return $meta_boxes; } //Function to dispay the field on the product-category page add_action( 'woocommerce_after_shop_loop', 'product_category_intro', 13, 3 ); function product_category_intro() { $value = rwmb_meta( 'textarea_1jtphdq0vy' ); echo $value; }The metabox is displaying correctly. But the field is not visible on the product category page. What am I doning wring here?
This is the product category page that I tested: https://bloemenbezorgenhaarlem.com/product-categorie/rozen/
September 17, 2020 at 11:17 PM #21925Long Nguyen
ModeratorHi,
To get field value from terms, we have to use this format.
rwmb_meta( $field_id, array( 'object_type' => 'term' ), $term_id )Also, this action hook does not accept any arguments so you should remove 3 after 13. The code should be:
//Function to dispay the field on the product-category page add_action( 'woocommerce_after_shop_loop', 'product_category_intro', 13 ); function product_category_intro() { $term_id = get_queried_object_id(); $value = rwmb_meta( 'textarea_1jtphdq0vy', array( 'object_type' => 'term' ), $term_id ); echo $value; }For more information, please follow this documentation https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value.
September 18, 2020 at 12:11 AM #21927[email protected]
ParticipantThank you Long, that did the trick.
Is there a way to change the order of the custom metabox? I would like the new metabox to be shown as 1st in the list.
Kind regards, Jan
September 18, 2020 at 9:05 AM #21931Long Nguyen
ModeratorHi,
This CSS code (admin area) would help you to show the term meta box first, above the default form.
.taxonomy-product_cat form#edittag { display: flex; flex-wrap: wrap; } .taxonomy-product_cat form#edittag .rwmb-meta-box { order: -1 }Apply the admin CSS code with this plugin https://wordpress.org/plugins/admin-css-mu/.
-
AuthorPosts
- You must be logged in to reply to this topic.