• Resolved alexiusgrey

    (@alexiusgrey)


    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?
    $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.

    
    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' ] )
    	);
     
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Thread Starter alexiusgrey

    (@alexiusgrey)

    Thanks, I’ll write them too

    Thread Starter alexiusgrey

    (@alexiusgrey)

    One person helped me in stackoverflow, that was a decision, if someone will be in my situation. Not pretty yet, but I can see the color.

     <div class="d-flex">
    <?php 
    $terms = get_terms( 'pa_color' );
     if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ ?>
         <ul>
         <?php  
         foreach ( $terms as $term ) {?>
         <li><a href="<?php echo get_term_link( $term )?>"><div class="pa_color-bg" style=" border: 1px solid; background: <?php echo get_term_meta( $term->term_id, 'hemename_pa_color', true ); ?> ">●</div> <span><?php echo $term->name ?></span></a></li> <?php       
         }     
     }
     ?>
    </ul>
    </div>
    .pa_color-bg{
        border: 1px solid;    
        width: 25px;
        height: 25px;
        border-radius: 50%;
        color: transparent;
        display: inline-block;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How can I get my custom term field value? No plugins(only wc)’ is closed to new replies.