Last active
November 12, 2023 09:16
-
-
Save codersaiful/30bac6b02636b8cda86e1e04b9dcb78a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Default Quantity Handle for old user | |
* Actually I have removed default quanity feature for new version. | |
* | |
* @author Saiful Islam <[email protected]> | |
* @link https://github.com/codersaiful | |
*/ | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment