/    Sign up×
Community /Pin to ProfileBookmark

Category Selection Problem

Hello everyone,
I’m working on a multi-vendor plugin (Dokan Pro).

I have Main Categories for Women, Men and Kids. Below them are the clothing categories. There are T-shirt under clothing.

So,
Women> Clothing> T-shirt
Men’s> Clothing> T-shirt
Kids> Clothing> T-shirt.

Vendor searches in the -Select Category- section while adding products. For example, T-shirt.

Three different trousers appear and the main categories do not appear (For example, Women, Men and Children).

In such a case, of course the vendor cannot make the right choice. What would you suggest for this ?
The corresponding code is below:

“`
<?php if ( dokan_get_option( ‘product_category_style’, ‘dokan_selling’, ‘single’ ) == ‘single’ ): ?>
<div class=”dokan-form-group”>
<label for=”product_cat” class=”form-label”><?php esc_html_e( ‘Category’, ‘dokan-lite’ ); ?></label>
<?php
$product_cat = -1;
$term = array();
$term = wp_get_post_terms( $post_id, ‘product_cat’, array( ‘fields’ => ‘ids’) );

if ( $term ) {
$product_cat = reset( $term );
}
include_once DOKAN_LIB_DIR.’/class.category-walker.php’;

$category_args = array(
‘show_option_none’ => __( ‘- Select a category -‘, ‘dokan-lite’ ),
‘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,
‘walker’ => new CategoryDropdownSingle( $post_id )
);

wp_dropdown_categories( apply_filters( ‘dokan_product_cat_dropdown_args’, $category_args ) );
?>
“`

Update,
This came to my mind. ([Image](https://i.ibb.co/2cXKZgb/abc.png))
Is it possible to rewrite the code this way?
Or any other idea?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@VITSUSAJan 19.2021 — Code is right. Try (brand name + product name) simultaneously, then it will help to find out exact product category as well as in sub category.
Copy linkTweet thisAlerts:
@JennieMillerJan 19.2021 — thanks for discus this problem.
Copy linkTweet thisAlerts:
@wpdevelislauthorJan 19.2021 — @VITSUSA#1626921

Thanks for your answer.

I could not understand what you mean. What does it have to do with the brand?

This category opens as below when no search is made. The subcategory shifts slightly to the right.

Clothing>Tshirt.

Please look at the image: [(Image)](https://i.ibb.co/HHcks28/abcd.png )
×

Success!

Help @wpdevelisl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...