Previous Code is not working for Taxonomy/Category
So use updated Code.
You also can get code from Github Gist: https://gist.github.com/codersaiful/30bac6b02636b8cda86e1e04b9dcb78a
add_filter('wcmmq_default_qty_option', '__return_true');
add_filter('wcmmq_single_product_min_max_condition', 'wcmmq_custom_default_value_enable', 10, 2);
function wcmmq_custom_default_value_enable($args, $product){
if(!defined('WC_MMQ_PREFIX')) return $args;
$product_id = $product->get_id();
$key = WC_MMQ_PREFIX . 'default_quantity';
$default_value = get_post_meta($product_id, $key, true);
if(!empty($default_value) && is_single()){
$args['input_value'] = $default_value;
}
$options = WC_MMQ::getOptions();
$termwise_args = false;
$term_data = $options['terms'] ?? [];
foreach( $term_data as $term_key => $values ){
//thats keys of this term, already in database, jeta setting theke fix/thk kora ache
$db_term_ids = array_keys($values);
$product_term_ids = wp_get_post_terms( $product_id, $term_key, array( 'fields' => 'ids' ));
$common_term_ids = array_intersect($db_term_ids, $product_term_ids);
if( empty( $common_term_ids ) ) continue;
$common_term_id = end($common_term_ids);
$termwise_args = $values[$common_term_id];
break;
}
$default_value = $termwise_args['_default'] ?? false;
if(empty($default_value)){
$options = WC_MMQ::getOptions();
$default_value = $options[$key];
}
if(!empty($default_value) && is_single()){
$args['input_value'] = $default_value;
}
return $args;
}
-
This reply was modified 1 year ago by Saiful Islam. Reason: Code Update