2014-10-17 96 views
0

我需要在後端右側的「產品類別」部分更改下拉菜單選項。woocommerce後端下拉式產品類別

有人知道,我如何在woocommerce中做到這一點?

謝謝

加布

編輯:

我有一個類別結構是這樣的: courses (primary category) -french (sub-category) -english (sub-category) --ireland (sub-category) ---Cork (sub-category) ---- school (sub-category)

,如果有可能我需要過濾後,我選擇的每個小類層次結構中上面的類別。

這是我做了什麼修改代碼

http://imageshack.com/a/img537/6404/iFstCU.png

http://imageshack.com/a/img674/8991/OL9BqP.png

+0

我發現這個http://tinyurl.com/6xc72h,但我不知道它是否對我的需求有用。 – GabrieleU 2014-10-17 14:49:19

回答

0

你可以試試這個代碼(你可以把這段代碼在你的主題function.php文件):

add_filter('woocommerce_taxonomy_args_product_cat', 'add_callback_for_product_cat'); 

function add_callback_for_product_cat($args) { 
    $args['meta_box_cb'] = 'replace_with_product_categories_dropdown'; 
    return $args; 
} 

function replace_with_product_categories_dropdown($post, $box) { 
    $defaults = array('taxonomy' => 'category'); 
    if (! isset($box['args']) || ! is_array($box['args'])) { 
     $args = array(); 
    } else { 
     $args = $box['args']; 
    } 
    $r = wp_parse_args($args, $defaults); 
    $tax_name = esc_attr($r['taxonomy']); 
    $taxonomy = get_taxonomy($r['taxonomy']); 
    ?> 
    <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> 
     <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> 
      <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> 
      <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li> 
     </ul> 

     <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;"> 
      <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" > 
       <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?> 
      </ul> 
     </div> 

     <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> 
      <?php 
      $name = ($tax_name == 'category') ? 'post_category' : 'tax_input[' . $tax_name . ']'; 
      echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. 
      $wp_dropdown_categories_args = array(
         'hierarchical'  => 1, 
         'name'    => 'product_cat_select', 
         'id'     => 'product_cat_select', 
         'class'    => 'postbox', 
         'taxonomy'   => 'product_cat' 
        ); 
      wp_dropdown_categories($wp_dropdown_categories_args); 
      ?> 
     </div> 
    <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?> 
      <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children"> 
       <h4> 
        <a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> 
         <?php 
          /* translators: %s: add new taxonomy label */ 
          printf(__('+ %s'), $taxonomy->labels->add_new_item); 
         ?> 
        </a> 
       </h4> 
       <p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> 
        <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> 
        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/> 
        <label class="screen-reader-text" for="new<?php echo $tax_name; ?>_parent"> 
         <?php echo $taxonomy->labels->parent_item_colon; ?> 
        </label> 
        <?php wp_dropdown_categories(array('taxonomy' => $tax_name, 'hide_empty' => 0, 'name' => 'new' . $tax_name . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;')); ?> 
        <input type="button" id="<?php echo $tax_name; ?>-add-submit" data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add" class="button category-add-submit" value="<?php echo esc_attr($taxonomy->labels->add_new_item); ?>" /> 
        <?php wp_nonce_field('add-' . $tax_name, '_ajax_nonce-add-' . $tax_name, false); ?> 
        <span id="<?php echo $tax_name; ?>-ajax-response"></span> 
       </p> 
      </div> 
     <?php endif; ?> 
    </div> 
    <?php 
} 

希望這會有所幫助。

+0

感謝您的幫助,我試圖修改您的代碼以滿足我的需求。你可以檢查以上嗎? – GabrieleU 2014-10-20 16:20:57