سلام من به ووکامرس یک taxonomy اضافه کردم که دست بندی دوم محصولات هستش .
که با کد زیر ایجاد کردم و بخوبی کار میکنه و سیو میشه .
function tr_create_my_taxonomy_brand() {
register_taxonomy(
'brand',
'product',
array(
'label' => __( 'برند' ),
'rewrite' => array( 'slug' => 'brand' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'tr_create_my_taxonomy_brand' );
حالا من میخوام این قابلیت رو به افزونه دکان اضافه کنم که تا حدودی انجام دادم ولی وقتی انتشار و ویرایش محصول رو با استفاده از افزونه دکان میزنم ، رفرش میشه ولی توی فیلد دسته بندی دوم هیچ تغییری بوجود نمیاد .
خود دکان از کد زیر برای دسته بندی استفاده میکنه .
<?php if ( dokan_get_option( 'product_category_style', 'dokan_selling', 'single' ) == 'single' ): ?>
<div class="dokan-form-group">
<?php
$product_cat = -1;
$term = array();
$term = wp_get_post_terms( $post_id, 'product_cat', array( 'fields' => 'ids') );
if ( $term ) {
$product_cat = reset( $term );
}
$category_args = array(
'show_option_none' => __( '- Select a category -', 'dokan' ),
'hierarchical' => 1,
'hide_empty' => 0,
'name' => 'product_cat',
'id' => 'product_cat',
'taxonomy' => 'product_cat',
'title_li' => '',
'class' => 'product_cat dokan-form-control dokan-select2',
'exclude' => '',
'selected' => $product_cat,
);
wp_dropdown_categories( apply_filters( 'dokan_product_cat_dropdown_args', $category_args ) );
?>
</div>
<?php endif; ?>
و کدی که من برای دسته بندی دوم استفاده کردم به شکل زیر می باشد .
<div class="dokan-form-group">
<?php
$product_cat = -1;
$term = array();
$term = wp_get_post_terms( $post_id, 'brand', 'product', array( 'fields' => 'ids'
) );
if ( $term ) {
$product_cat = reset( $term );
}
$category_args = array(
'show_option_none' => __( '- Select a category -', 'dokan' ),
'hierarchical' => 1,
'hide_empty' => 0,
'name' => 'brand',
'id' => 'product_cat',
'taxonomy' => 'brand',
'title_li' => '',
'class' => 'product_cat dokan-form-control dokan-select2',
'exclude' => '',
'selected' => $brand,
);
wp_dropdown_categories( apply_filters( 'dokan_product_cat_dropdown_args', $category_args ) );
?>
</div>
باید به چه صورت تغییر بدم تا درست بشه ؟
که با کد زیر ایجاد کردم و بخوبی کار میکنه و سیو میشه .
function tr_create_my_taxonomy_brand() {
register_taxonomy(
'brand',
'product',
array(
'label' => __( 'برند' ),
'rewrite' => array( 'slug' => 'brand' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'tr_create_my_taxonomy_brand' );
حالا من میخوام این قابلیت رو به افزونه دکان اضافه کنم که تا حدودی انجام دادم ولی وقتی انتشار و ویرایش محصول رو با استفاده از افزونه دکان میزنم ، رفرش میشه ولی توی فیلد دسته بندی دوم هیچ تغییری بوجود نمیاد .
خود دکان از کد زیر برای دسته بندی استفاده میکنه .
<?php if ( dokan_get_option( 'product_category_style', 'dokan_selling', 'single' ) == 'single' ): ?>
<div class="dokan-form-group">
<?php
$product_cat = -1;
$term = array();
$term = wp_get_post_terms( $post_id, 'product_cat', array( 'fields' => 'ids') );
if ( $term ) {
$product_cat = reset( $term );
}
$category_args = array(
'show_option_none' => __( '- Select a category -', 'dokan' ),
'hierarchical' => 1,
'hide_empty' => 0,
'name' => 'product_cat',
'id' => 'product_cat',
'taxonomy' => 'product_cat',
'title_li' => '',
'class' => 'product_cat dokan-form-control dokan-select2',
'exclude' => '',
'selected' => $product_cat,
);
wp_dropdown_categories( apply_filters( 'dokan_product_cat_dropdown_args', $category_args ) );
?>
</div>
<?php endif; ?>
و کدی که من برای دسته بندی دوم استفاده کردم به شکل زیر می باشد .
<div class="dokan-form-group">
<?php
$product_cat = -1;
$term = array();
$term = wp_get_post_terms( $post_id, 'brand', 'product', array( 'fields' => 'ids'
) );
if ( $term ) {
$product_cat = reset( $term );
}
$category_args = array(
'show_option_none' => __( '- Select a category -', 'dokan' ),
'hierarchical' => 1,
'hide_empty' => 0,
'name' => 'brand',
'id' => 'product_cat',
'taxonomy' => 'brand',
'title_li' => '',
'class' => 'product_cat dokan-form-control dokan-select2',
'exclude' => '',
'selected' => $brand,
);
wp_dropdown_categories( apply_filters( 'dokan_product_cat_dropdown_args', $category_args ) );
?>
</div>
باید به چه صورت تغییر بدم تا درست بشه ؟