Get the minimum variation price in WooCommerce

Viewed 14097

I am a beginner trying to learn Wordpress and have a variable product with prices:

  • cod Rs 250
  • online Rs 200

I want to use the minimum price in my themes functions.php.

How will I be able to fetch or get the minimum value?

I want to use in the below code :

function filter_gateways($gateways){

    $payment_NAME = 'cod'; // 
    $min_variation_price = ''; <--------------- minimum variation price

    global $woocommerce;

    foreach ($woocommerce->cart->cart_contents as $key => $values ) {
        // Get the terms, i.e. category list using the ID of the product
        $terms = get_the_terms( $values['product_id'], 'product_cat' );
        // Because a product can have multiple categories, we need to iterate through the list of the products category for a match
        foreach ($terms as $term) {
            // 20 is the ID of the category for which we want to remove the payment gateway
            if($term->term_id == $min_variation_price){
                unset($gateways[$payment_NAME]);
                // If you want to remove another payment gateway, add it here i.e. unset($gateways['cod']);
                break;
            }
            break;
        }
    }
    return $gateways;
}
2 Answers
Related