2021年1月29日星期五

How can I get my custom term field value in WooCommerce?

I've created the 'color field' for pa_color taxonomy terms, by native ways, but how can I get their values to the place I need?

This is my code:

add_action( 'pa_color_add_form_fields', 'themename_pa_color_add_term_fields' );     function themename_pa_color_add_term_fields( $taxonomy ) {   ?>      <div class="form-field">      <label for="themename_pa_color">PA Color</label>      <input type="color" name="themename_pa_color" id="themename_pa_color" class="wpColorChoose" />      <p>Field description may go here.</p>      </div>;   <?php   }    add_action( 'pa_color_edit_form_fields', 'themename_pa_color_edit_term_fields', 10, 2 );     function themename_pa_color_edit_term_fields( $term, $taxonomy ) {         $value = get_term_meta( $term->term_id, 'themename_pa_color', true );         echo '<tr class="form-field">      <th>          <label for="themename_pa_color">PA Color</label>      </th>      <td>          <input name="themename_pa_color" id="themename_pa_color" type="color" class="wpColorChoose" value="' . esc_attr( $value ) .'" />          <p class="description">Field description may go here.</p>      </td>      </tr>';     }    add_action( 'created_pa_color', 'themename_pa_color_save_term_fields' );  add_action( 'edited_pa_color', 'themename_pa_color_save_term_fields' );     function themename_pa_color_save_term_fields( $term_id ) {         update_term_meta(          $term_id,          'themename_pa_color',          sanitize_text_field( $_POST[ 'themename_pa_color' ] )      );     }  

Using $term->themename_pa_color doesn't work.

It works with name and description default fields, like $term->name or $term->description, but not with my field.

That's how I created it, it correctly saves values.

https://stackoverflow.com/questions/65963718/how-can-i-get-my-custom-term-field-value-in-woocommerce January 30, 2021 at 09:15AM

没有评论:

发表评论