function test_get_min_price() { $args = array('name' => 'My Service 1', 'price' => 1.1); appointments_insert_service($args); $args = array('name' => 'My Service 2', 'price' => 0.5); appointments_insert_service($args); $args = array('name' => 'My Service 3', 'price' => 10); appointments_insert_service($args); $price = appointments_get_services_min_price(); $this->assertEquals(0.5, $price); }
/** * Adds and returns a variation to the app product * @Since 1.0.1 */ function add_variation($app_id, $post_id, $service, $worker, $start, $end) { $meta = get_post_meta($post_id, 'mp_var_name', true); // MP requires at least 2 variations, so we add a dummy one if there is none if (!$meta || !is_array($meta)) { add_post_meta($post_id, 'mp_var_name', array(0)); add_post_meta($post_id, 'mp_sku', array(0)); // Find minimum service price here: global $wpdb; $min_price = appointments_get_services_min_price(); add_post_meta($post_id, 'mp_price', array($min_price)); // Variation ID $meta = array(0); } $max = count($meta); $meta[$max] = $app_id; update_post_meta($post_id, 'mp_var_name', $meta); $sku = get_post_meta($post_id, 'mp_sku', true); $sku[$max] = $this->_core->service; update_post_meta($post_id, 'mp_sku', $sku); $price = get_post_meta($post_id, 'mp_price', true); $price[$max] = apply_filters('app_mp_price', $this->_core->get_price(true), $service, $worker, $start, $end); // Filter added at V1.2.3.1 update_post_meta($post_id, 'mp_price', $price); // Add a download link, so that app will be a digital product $file = get_post_meta($post_id, 'mp_file', true); if (!$file) { add_post_meta($post_id, 'mp_file', get_permalink($post_id)); } return $max; }