Site icon Hip-Hop Website Design and Development

woocommerce product sorting based mostly on customized fields [closed]

I’m making an attempt so as to add a customized sorting choice for woo commerce . So I’m utilizing following code so as to add new type choice plus set it as default

meta key’s ‘_am_cat_sort’

operate sv_personagem_woocommerce_shop_ordering( $sort_args ) {
  $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );

    if ( 'personagem' == $orderby_value ) {
        $sort_args['orderby'] = '_am_cat_sort';
        $sort_args['order'] = 'ASC';
        $sort_args['meta_key'] = '';
    }

    return $sort_args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'sv_personagem_woocommerce_shop_ordering' );

operate sv_custom_woocommerce_catalog_orderby( $sortby ) {
    $sortby['personagem'] = 'Type by cat: personagem';
    return $sortby;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'sv_custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'sv_custom_woocommerce_catalog_orderby' );

add_filter('woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby');

operate custom_default_catalog_orderby() {
     return 'personagem'; // May also use title and value
}

Now following is the code I’m utilizing so as to add new meta area

add_action('add_meta_boxes', 'add_am_product_metaboxes');

operate add_am_product_metaboxes() {
add_meta_box('wpt_am_product', __('Type worth'), 'wpt_am_product', 'product', 'regular', 'excessive', null);
}

operate wpt_am_product(){
  // Add the HTML for the submit meta
  world $submit;
  // Noncename wanted to confirm the place the info originated
  wp_nonce_field( 'oj-am_product-fields', 'oj-am_product-fields_wpnonce', false, true );
  // Get the placement information if its already been entered 

  $am_cat_sort  = get_post_meta($post->ID,  '_am_cat_sort', true);
  $am_cat_sort  = (int)$am_cat_sort; 
  $phrases = wp_get_post_terms( $post->ID, 'product_cat' );
  $myterms=array();
  foreach ($phrases as $time period) {
    $myterms[]=$term->term_id;
   } 
  if(in_array(76, $myterms)){
    $am_cat_sort  = -99;
  }else{
    $am_cat_sort  = 0;
  }

  echo '<label >';?><?php _e( 'type order' );?></label> 
  <?php echo '<br><textarea  identify="_am_cat_sort" rows="4" cols="80">'.$am_cat_sort.'</textarea>'.'<br>'; 

}

However sorting isn’t working in any respect

Thanks prematurely