• ResolvedPlugin Author Saiful Islam

    (@codersaiful)


    for security perpose, we have disable default value option in our plugin. Actually it’s conflicting with all type side cart plugin. That’s why we have disable it from our plugin. But if you still want ‘default value’ option,
    use code inside your theme’s functions.php file from following link.
    we recommend child theme obviously.

    https://gist.github.com/codersaiful/bb7888558949a1a0863ea313117a14d5

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Saiful Islam

    (@codersaiful)

    <?php
    
    //COPY THIS BELLOW LINE ONLY TO PASTE IN YOUR functions.php
    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)){
    		$options = \WC_MMQ::getOptions();
    		$default_value = $options[$key];
    	}
    	if(!empty($default_value) && is_single()){
    		$args['input_value'] = $default_value;
    	}
    	return $args;
    }
    
    
    
    
    /**
    for security perpose, we have disable default value option in our plugin. Actually it’s conflicting with all type side cart plugin. That’s why we have disable it from our plugin. But if you still want ‘default value’ option,
    use following code inside your theme’s functions.php file.
    we recommend child theme obviously.
    */
    Plugin Author Saiful Islam

    (@codersaiful)

    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
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘default value option is not working – how to enable?’ is closed to new replies.