/**
 * Enqueue the price calculator admin scripts
 */
function wc_measurement_price_calculator_admin_enqueue_scripts()
{
    global $taxnow, $post;
    // Get admin screen id
    $screen = get_current_screen();
    // on the admin product page
    if ('product' == $screen->id) {
        wp_enqueue_script('wc-price-calculator-admin', wc_measurement_price_calculator()->get_plugin_url() . '/assets/js/admin/wc-measurement-price-calculator.min.js');
        // Variables for JS scripts
        $wc_price_calculator_admin_params = array('woocommerce_currency_symbol' => get_woocommerce_currency_symbol(), 'woocommerce_weight_unit' => 'no' !== get_option('woocommerce_enable_weight', true) ? get_option('woocommerce_weight_unit') : '');
        wp_localize_script('wc-price-calculator-admin', 'wc_price_calculator_admin_params', $wc_price_calculator_admin_params);
    }
}
/**
 * Adds the Calculator tab panel to the Product Data postbox in the product interface
 */
function wc_price_calculator_product_rates_panel_content()
{
    global $post;
    $measurement_units = array('weight' => wc_measurement_price_calculator_get_weight_units(), 'dimension' => wc_measurement_price_calculator_get_dimension_units(), 'area' => wc_measurement_price_calculator_get_area_units(), 'volume' => wc_measurement_price_calculator_get_volume_units());
    ?>
	<div id="measurement_product_data" class="panel woocommerce_options_panel">
		<style type="text/css">
			#measurement_product_data hr { height:2px; border-style:none; border-bottom:solid 1px white; color:#DFDFDF; background-color:#DFDFDF; }
			.measurement-subnav { margin:14px 12px; }
			.measurement-subnav a { text-decoration:none; }
			.measurement-subnav a.active { color:black; font-weight:bold; }
			.measurement-subnav a.disabled { color: #8A7F7F; cursor: default; }
			#measurement_product_data .wc-calculator-pricing-table td.wc-calculator-pricing-rule-range input { float:none; width:auto; }
			#measurement_product_data table.wc-calculator-pricing-table { margin: 12px; width: 95%; }
			#measurement_product_data table.wc-calculator-pricing-table td { padding: 10px 7px 10px; cursor: move; }
			#measurement_product_data table.wc-calculator-pricing-table button { font-family: sans-serif; }
			#measurement_product_data table.wc-calculator-pricing-table button.wc-calculator-pricing-table-delete-rules { float: right; }
		</style>
		<div class="measurement-subnav">
			<a class="active" href="#calculator-settings"><?php 
    _e('Calculator Settings', WC_Measurement_Price_Calculator::TEXT_DOMAIN);
    ?>
</a> |
			<a class="wc-measurement-price-calculator-pricing-table" href="#calculator-pricing-table"><?php 
    _e('Pricing Table', WC_Measurement_Price_Calculator::TEXT_DOMAIN);
    ?>
</a>
		</div>
		<hr/>
		<?php 
    $settings = new WC_Price_Calculator_Settings($post->ID);
    $pricing_weight_wrapper_class = '';
    if ('no' === get_option('woocommerce_enable_weight', true)) {
        $pricing_weight_wrapper_class = 'hidden';
    }
    $settings = $settings->get_raw_settings();
    // we want the underlying raw settings array
    $calculator_options = array('' => __('None', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'dimension' => __('Dimensions', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'area' => __('Area', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'area-dimension' => __('Area (LxW)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'area-linear' => __('Perimeter (2L + 2W)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'area-surface' => __('Surface Area 2(LW + LH + WH)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'volume' => __('Volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'volume-dimension' => __('Volume (LxWxH)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'volume-area' => __('Volume (AxH)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'weight' => __('Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'wall-dimension' => __('Room Walls', WC_Measurement_Price_Calculator::TEXT_DOMAIN));
    echo '<div id="calculator-settings" class="calculator-subpanel">';
    // Measurement select
    woocommerce_wp_select(array('id' => '_measurement_price_calculator', 'value' => $settings['calculator_type'], 'label' => __('Measurement', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $calculator_options, 'description' => __('Select the product measurement to calculate quantity by or define pricing within.', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<p id="area-dimension_description" class="measurement_description" style="display:none;">' . __("Use this measurement to have the customer prompted for a length and width to calculate the area required.  When pricing is disabled (no custom dimensions) this calculator uses the product area attribute or otherwise the length and width attributes to determine the product area.", WC_Measurement_Price_Calculator::TEXT_DOMAIN) . '</p>';
    echo '<p id="area-linear_description" class="measurement_description" style="display:none;">' . __("Use this measurement to have the customer prompted for a length and width to calculate the linear distance (L * 2 + W * 2).", WC_Measurement_Price_Calculator::TEXT_DOMAIN) . '</p>';
    echo '<p id="area-surface_description" class="measurement_description" style="display:none;">' . __("Use this measurement to have the customer prompted for a length, width and height to calculate the surface area 2 * (L * W + W * H + L * H).", WC_Measurement_Price_Calculator::TEXT_DOMAIN) . '</p>';
    echo '<p id="volume-dimension_description" class="measurement_description" style="display:none;">' . __("Use this measurement to have the customer prompted for a length, width and height to calculate the volume required.  When pricing is disabled (no custom dimensions) this calculator uses the product volume attribute or otherwise the length, width and height attributes to determine the product volume.", WC_Measurement_Price_Calculator::TEXT_DOMAIN) . '</p>';
    echo '<p id="volume-area_description" class="measurement_description" style="display:none;">' . __("Use this measurement to have the customer prompted for an area and height to calculate the volume required.  When pricing is disabled (no custom dimensions) this calculator uses the product volume attribute or otherwise the length, width and height attributes to determine the product volume.", WC_Measurement_Price_Calculator::TEXT_DOMAIN) . '</p>';
    echo '<p id="wall-dimension_description" class="measurement_description" style="display:none;">' . __("Use this measurement for applications such as wallpaper; the customer will be prompted for the wall height and distance around the room.  When pricing is disabled (no custom dimensions) this calculator uses the product area attribute or otherwise the length and width attributes to determine the wall surface area.", WC_Measurement_Price_Calculator::TEXT_DOMAIN) . '</p>';
    echo '<div id="dimension_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_dimension_pricing', 'value' => $settings['dimension']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_dimension_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_dimension_pricing_label', 'value' => $settings['dimension']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_dimension_pricing_unit', 'value' => $settings['dimension']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_dimension_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['dimension']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_dimension_pricing_weight_enabled', 'value' => $settings['dimension']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product dimension', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_dimension_pricing_inventory_enabled', 'value' => $settings['dimension']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product dimension', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    // Dimension - Length
    wc_measurement_price_calculator_wp_radio(array('name' => '_measurement_dimension', 'id' => '_measurement_dimension_length', 'rbvalue' => 'length', 'value' => 'yes' == $settings['dimension']['length']['enabled'] ? 'length' : '', 'class' => 'checkbox _measurement_dimension', 'label' => __('Length', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Select to display the product length in the price calculator', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_dimension_length_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_dimension_length_label', 'value' => $settings['dimension']['length']['label'], 'label' => __('Length Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Length input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_dimension_length_unit', 'value' => $settings['dimension']['length']['unit'], 'label' => __('Length Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend length input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_dimension_length_editable', 'value' => $settings['dimension']['length']['editable'], 'label' => __('Length Editable', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'class' => 'checkbox _measurement_editable', 'description' => __('Check this box to allow the needed length to be entered by the customer', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_text_input(array('id' => '_measurement_dimension_length_options', 'value' => implode(', ', $settings['dimension']['length']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Length Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    echo '<hr/>';
    // Dimension - Width
    wc_measurement_price_calculator_wp_radio(array('name' => '_measurement_dimension', 'id' => '_measurement_dimension_width', 'rbvalue' => 'width', 'value' => 'yes' == $settings['dimension']['width']['enabled'] ? 'width' : '', 'class' => 'checkbox _measurement_dimension', 'label' => __('Width', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Select to display the product width in the price calculator', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_dimension_width_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_dimension_width_label', 'value' => $settings['dimension']['width']['label'], 'label' => __('Width Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Width input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_dimension_width_unit', 'value' => $settings['dimension']['width']['unit'], 'label' => __('Width Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend width input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_dimension_width_editable', 'value' => $settings['dimension']['width']['editable'], 'label' => __('Width Editable', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'class' => 'checkbox _measurement_editable', 'description' => __('Check this box to allow the needed width to be entered by the customer', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_text_input(array('id' => '_measurement_dimension_width_options', 'value' => implode(', ', $settings['dimension']['width']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Width Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    echo '<hr/>';
    // Dimension - Height
    wc_measurement_price_calculator_wp_radio(array('name' => '_measurement_dimension', 'id' => '_measurement_dimension_height', 'rbvalue' => 'height', 'value' => 'yes' == $settings['dimension']['height']['enabled'] ? 'height' : '', 'class' => 'checkbox _measurement_dimension', 'label' => __('Height', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Select to display the product height in the price calculator', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_dimension_height_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_dimension_height_label', 'value' => $settings['dimension']['height']['label'], 'label' => __('Height Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Height input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_dimension_height_unit', 'value' => $settings['dimension']['height']['unit'], 'label' => __('Height Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend height input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_dimension_height_editable', 'value' => $settings['dimension']['height']['editable'], 'label' => __('Height Editable', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'class' => 'checkbox _measurement_editable', 'description' => __('Check this box to allow the needed height to be entered by the customer', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_text_input(array('id' => '_measurement_dimension_height_options', 'value' => implode(', ', $settings['dimension']['height']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Height Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    echo '</div>';
    // Area
    echo '<div id="area_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_area_pricing', 'value' => $settings['area']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_area_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_area_pricing_label', 'value' => $settings['area']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area_pricing_unit', 'value' => $settings['area']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['area'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_area_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['area']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area_pricing_weight_enabled', 'value' => $settings['area']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area_pricing_inventory_enabled', 'value' => $settings['area']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area_label', 'value' => $settings['area']['area']['label'], 'label' => __('Area Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Area input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area_unit', 'value' => $settings['area']['area']['unit'], 'label' => __('Area Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['area'], 'description' => __('The frontend area input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_area_editable', 'value' => $settings['area']['area']['editable'], 'label' => __('Editable', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'class' => 'checkbox _measurement_editable', 'description' => __('Check this box to allow the needed measurement to be entered by the customer', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_text_input(array('id' => '_measurement_area_options', 'value' => implode(', ', $settings['area']['area']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Area Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // Area (LxW)
    echo '<div id="area-dimension_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_area-dimension_pricing', 'value' => $settings['area-dimension']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_area-dimension_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_area-dimension_pricing_label', 'value' => $settings['area-dimension']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-dimension_pricing_unit', 'value' => $settings['area-dimension']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['area'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-dimension_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['area-dimension']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-dimension_pricing_weight_enabled', 'value' => $settings['area-dimension']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-dimension_pricing_inventory_enabled', 'value' => $settings['area-dimension']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area_length_label', 'value' => $settings['area-dimension']['length']['label'], 'label' => __('Length Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Length input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area_length_unit', 'value' => $settings['area-dimension']['length']['unit'], 'label' => __('Length Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend length input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_area_length_options', 'value' => implode(', ', $settings['area-dimension']['length']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Length Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area_width_label', 'value' => $settings['area-dimension']['width']['label'], 'label' => __('Width Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Width input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area_width_unit', 'value' => $settings['area-dimension']['width']['unit'], 'label' => __('Width Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend width input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_area_width_options', 'value' => implode(', ', $settings['area-dimension']['width']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Width Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // Perimeter (2 * L + 2 * W)
    echo '<div id="area-linear_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_area-linear_pricing', 'value' => $settings['area-linear']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_area-linear_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_area-linear_pricing_label', 'value' => $settings['area-linear']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-linear_pricing_unit', 'value' => $settings['area-linear']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-linear_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['area-linear']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-linear_pricing_weight_enabled', 'value' => $settings['area-linear']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-linear_pricing_inventory_enabled', 'value' => $settings['area-linear']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area-linear_length_label', 'value' => $settings['area-linear']['length']['label'], 'label' => __('Length Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Length input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-linear_length_unit', 'value' => $settings['area-linear']['length']['unit'], 'label' => __('Length Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend length input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_area-linear_length_options', 'value' => implode(', ', $settings['area-linear']['length']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Length Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area-linear_width_label', 'value' => $settings['area-linear']['width']['label'], 'label' => __('Width Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Width input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-linear_width_unit', 'value' => $settings['area-linear']['width']['unit'], 'label' => __('Width Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend width input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_area-linear_width_options', 'value' => implode(', ', $settings['area-linear']['width']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Width Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // Surface Area 2 * (L * W + W * H + L * H)
    echo '<div id="area-surface_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_area-surface_pricing', 'value' => $settings['area-surface']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_area-surface_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_area-surface_pricing_label', 'value' => $settings['area-surface']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-surface_pricing_unit', 'value' => $settings['area-surface']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['area'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-surface_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['area-surface']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-surface_pricing_weight_enabled', 'value' => $settings['area-surface']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_area-surface_pricing_inventory_enabled', 'value' => $settings['area-surface']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area-surface_length_label', 'value' => $settings['area-surface']['length']['label'], 'label' => __('Length Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Length input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-surface_length_unit', 'value' => $settings['area-surface']['length']['unit'], 'label' => __('Length Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend length input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_area-surface_length_options', 'value' => implode(', ', $settings['area-surface']['length']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Length Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area-surface_width_label', 'value' => $settings['area-surface']['width']['label'], 'label' => __('Width Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Width input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-surface_width_unit', 'value' => $settings['area-surface']['width']['unit'], 'label' => __('Width Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend width input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_area-surface_width_options', 'value' => implode(', ', $settings['area-surface']['width']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Width Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_area-surface_height_label', 'value' => $settings['area-surface']['height']['label'], 'label' => __('Height Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Height input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_area-surface_height_unit', 'value' => $settings['area-surface']['height']['unit'], 'label' => __('Height Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend height input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_area-surface_height_options', 'value' => implode(', ', $settings['area-surface']['height']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Height Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // Volume
    echo '<div id="volume_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_volume_pricing', 'value' => $settings['volume']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_volume_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_volume_pricing_label', 'value' => $settings['volume']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume_pricing_unit', 'value' => $settings['volume']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['volume'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['volume']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume_pricing_weight_enabled', 'value' => $settings['volume']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume_pricing_inventory_enabled', 'value' => $settings['volume']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_volume_label', 'value' => $settings['volume']['volume']['label'], 'label' => __('Volume Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Volume input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume_unit', 'value' => $settings['volume']['volume']['unit'], 'label' => __('Volume Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['volume'], 'description' => __('The frontend volume input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume_editable', 'value' => $settings['volume']['volume']['editable'], 'label' => __('Editable', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'class' => 'checkbox _measurement_editable', 'description' => __('Check this box to allow the needed measurement to be entered by the customer', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_text_input(array('id' => '_measurement_volume_options', 'value' => implode(', ', $settings['volume']['volume']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Volume Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // Volume (LxWxH)
    echo '<div id="volume-dimension_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-dimension_pricing', 'value' => $settings['volume-dimension']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_volume-dimension_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_volume-dimension_pricing_label', 'value' => $settings['volume-dimension']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume-dimension_pricing_unit', 'value' => $settings['volume-dimension']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['volume'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-dimension_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['volume-dimension']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-dimension_pricing_weight_enabled', 'value' => $settings['volume-dimension']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-dimension_pricing_inventory_enabled', 'value' => $settings['volume-dimension']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_volume_length_label', 'value' => $settings['volume-dimension']['length']['label'], 'label' => __('Length Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Length input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume_length_unit', 'value' => $settings['volume-dimension']['length']['unit'], 'label' => __('Length Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend length input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_volume_length_options', 'value' => implode(', ', $settings['volume-dimension']['length']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Length Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_volume_width_label', 'value' => $settings['volume-dimension']['width']['label'], 'label' => __('Width Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Width input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume_width_unit', 'value' => $settings['volume-dimension']['width']['unit'], 'label' => __('Width Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend width input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_volume_width_options', 'value' => implode(', ', $settings['volume-dimension']['width']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Width Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_volume_height_label', 'value' => $settings['volume-dimension']['height']['label'], 'label' => __('Height Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Height input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume_height_unit', 'value' => $settings['volume-dimension']['height']['unit'], 'label' => __('Height Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend height input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_volume_height_options', 'value' => implode(', ', $settings['volume-dimension']['height']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Height Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // Volume (AxH)
    echo '<div id="volume-area_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-area_pricing', 'value' => $settings['volume-area']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_volume-area_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_volume-area_pricing_label', 'value' => $settings['volume-area']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume-area_pricing_unit', 'value' => $settings['volume-area']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['volume'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-area_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['volume-area']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-area_pricing_weight_enabled', 'value' => $settings['volume-area']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_volume-area_pricing_inventory_enabled', 'value' => $settings['volume-area']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_volume_area_label', 'value' => $settings['volume-area']['area']['label'], 'label' => __('Area Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Area input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume_area_unit', 'value' => $settings['volume-area']['area']['unit'], 'label' => __('Area Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['area'], 'description' => __('The frontend area input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_volume_area_options', 'value' => implode(', ', $settings['volume-area']['area']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Area Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_volume_area_height_label', 'value' => $settings['volume-area']['height']['label'], 'label' => __('Height Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Height input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_volume_area_height_unit', 'value' => $settings['volume-area']['height']['unit'], 'label' => __('Height Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend height input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_volume_area_height_options', 'value' => implode(', ', $settings['volume-area']['height']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Height Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // Weight
    echo '<div id="weight_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_weight_pricing', 'value' => $settings['weight']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_weight_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_weight_pricing_label', 'value' => $settings['weight']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_weight_pricing_unit', 'value' => $settings['weight']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['weight'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_weight_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['weight']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_weight_pricing_weight_enabled', 'value' => $settings['weight']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to use the customer-configured product weight as the item weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_weight_pricing_inventory_enabled', 'value' => $settings['weight']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_weight_label', 'value' => $settings['weight']['weight']['label'], 'label' => __('Weight Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Weight input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_weight_unit', 'value' => $settings['weight']['weight']['unit'], 'label' => __('Weight Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['weight'], 'description' => __('The frontend weight input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_weight_editable', 'value' => $settings['weight']['weight']['editable'], 'label' => __('Editable', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'class' => 'checkbox _measurement_editable', 'description' => __('Check this box to allow the needed measurement to be entered by the customer', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_text_input(array('id' => '_measurement_weight_options', 'value' => implode(', ', $settings['weight']['weight']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Weight Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    // wall dimension is just the area-dimension calculator with different labels
    echo '<div id="wall-dimension_measurements" class="measurement_fields">';
    woocommerce_wp_checkbox(array('id' => '_measurement_wall-dimension_pricing', 'value' => $settings['wall-dimension']['pricing']['enabled'], 'class' => 'checkbox _measurement_pricing', 'label' => __('Show Product Price Per Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to display product pricing per unit on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '<div id="_measurement_wall-dimension_pricing_fields" class="_measurement_pricing_fields" style="display:none;">';
    woocommerce_wp_text_input(array('id' => '_measurement_wall-dimension_pricing_label', 'value' => $settings['wall-dimension']['pricing']['label'], 'label' => __('Pricing Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Label to display next to the product price (defaults to pricing unit)', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_wall-dimension_pricing_unit', 'value' => $settings['wall-dimension']['pricing']['unit'], 'class' => '_measurement_pricing_unit', 'label' => __('Pricing Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['area'], 'description' => __('Unit to define pricing in', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_checkbox(array('id' => '_measurement_wall-dimension_pricing_calculator_enabled', 'class' => 'checkbox _measurement_pricing_calculator_enabled', 'value' => $settings['wall-dimension']['pricing']['calculator']['enabled'], 'label' => __('Calculated Price', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define product pricing per unit and allow customers to provide custom measurements', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_wall-dimension_pricing_weight_enabled', 'value' => $settings['wall-dimension']['pricing']['weight']['enabled'], 'class' => 'checkbox _measurement_pricing_weight_enabled', 'wrapper_class' => $pricing_weight_wrapper_class . ' _measurement_pricing_calculator_fields', 'label' => __('Calculated Weight', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define the product weight per unit and calculate the item weight based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    woocommerce_wp_checkbox(array('id' => '_measurement_wall-dimension_pricing_inventory_enabled', 'value' => $settings['wall-dimension']['pricing']['inventory']['enabled'], 'class' => 'checkbox _measurement_pricing_inventory_enabled', 'wrapper_class' => 'stock_fields _measurement_pricing_calculator_fields', 'label' => __('Calculated Inventory', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Check this box to define inventory per unit and calculate inventory based on the product area', WC_Measurement_Price_Calculator::TEXT_DOMAIN)));
    echo '</div>';
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_wall_length_label', 'value' => $settings['wall-dimension']['length']['label'], 'label' => __('Length Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Wall length input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_wall_length_unit', 'value' => $settings['wall-dimension']['length']['unit'], 'label' => __('Length Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend wall length input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_wall_length_options', 'value' => implode(', ', $settings['wall-dimension']['length']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Length Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '<hr/>';
    woocommerce_wp_text_input(array('id' => '_measurement_wall_width_label', 'value' => $settings['wall-dimension']['width']['label'], 'label' => __('Height Label', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Room wall height input field label to display on the frontend', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_select(array('id' => '_measurement_wall_width_unit', 'value' => $settings['wall-dimension']['width']['unit'], 'label' => __('Height Unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'options' => $measurement_units['dimension'], 'description' => __('The frontend room wall height input field unit', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    woocommerce_wp_text_input(array('id' => '_measurement_wall_width_options', 'value' => implode(', ', $settings['wall-dimension']['width']['options']), 'wrapper_class' => '_measurement_pricing_calculator_fields', 'label' => __('Height Options', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'description' => __('Use a single number to set a fixed value for this field on the frontend, or a comma-separated list of numbers to create a select box for the customer to choose between.  Example: 1/8, .5, 2', WC_Measurement_Price_Calculator::TEXT_DOMAIN), 'desc_tip' => true));
    echo '</div>';
    echo '</div>';
    // close the subpanel
    echo '<div id="calculator-pricing-table" class="calculator-subpanel">';
    require_once wc_measurement_price_calculator()->get_plugin_path() . '/admin/post-types/writepanels/writepanel-product_data-pricing_table.php';
    echo '</div>';
    ?>

	</div>
	<?php 
}
 /**
  * Add the pricing calculator and quantity input if the user can view the price
  *
  * @since 3.7.0
  */
 public function catalog_visibility_options_pricing_calculator_quantity_input()
 {
     global $product;
     // bail if the calculator is not enabled for this product
     if (!$product || !WC_Price_Calculator_Product::calculator_enabled($product)) {
         return;
     }
     // bail if current user can't view the price
     if (class_exists('WC_Catalog_Restrictions_Filters') && !WC_Catalog_Restrictions_Filters::instance()->user_can_view_price($product)) {
         return;
     }
     // render pricing calculator
     wc_measurement_price_calculator()->get_product_page_instance()->render_price_calculator();
     // render quantity input
     if (!$product->is_sold_individually()) {
         woocommerce_quantity_input(array('min_value' => apply_filters('woocommerce_quantity_input_min', 1, $product), 'max_value' => apply_filters('woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product)));
     }
 }
function init_woocommerce_measurement_price_calculator()
{
    /**
     * # Main WooCommerce Measurement Price Calculator Class
     *
     * ## Plugin Overview
     *
     * This measurement price calculator plugin actually provides two seemingly
     * related but distinct operational modes:  a quantity calculator, and a
     * pricing calculator.
     *
     * The quantity calculator operates on the configured product dimensions and
     * allows the customer to specify the measurements they require.  This is
     * useful for a merchant that sells a product like boxed tiles which cover a
     * known square footage.  If a box covers 25 sq ft and the customer requires
     * 30 sq ft then the calculator will set the quantity to '2'.
     *
     * The pricing calculator allows the shopkeeper to define a price per unit
     * (ie $/ft) and then the customer supplies the measurements they want.  This
     * is ideal for a merchant that sells a product which is customized to order,
     * such as fabric.  They define a price per unit, and the customer enters the
     * dimensions required, and the quantity.  The customer-supplied measurements
     * are added as order meta data.
     *
     * ## Terminology
     *
     * + `Total measurement` - the total measurement for a product is the length/width/
     *   height for a dimension product, the area for an area/area (LxW) product,
     *   the volume for a volume/volume (AxH)/volume (LxWxH) and the weight for a
     *   weight product.
     *   Related terms: derived measurement, compound measurement
     *
     * + `Common unit` - a single unit "family" used when deriving a compound measurement from
     *   a set of simple measurements.  For instance when finding the Volume (AxH)
     *   the standard units for area and height could be 'sq. ft.' and 'ft' which
     *   when multiplied yield  the known unit 'cu. ft.'.  Without a common unit
     *   you could end up multiplying acres * cm, and what unit does that yield?
     *
     * + `Standard unit` - one of a limited number of units to which all other units
     *   are converted as an intermediate step before converting to a final desired
     *   unit.  This is used to solve the many-to-many problem of converting between
     *   two arbitrary units.  Using a set of standard units means we only need to
     *   know how to convert any arbitrary unit *to* one of the standard units, and
     *   *from* the set of standard units to any other arbitrary unit, which is a
     *   vastly simpler problem than knowing how to convert directly between any
     *   two arbitrary units.  A set of standard units is defined for each system
     *   of measurement (English and SI) so that unit conversion can generally take
     *   place within a single system of measurement, because converting between
     *   systems of measurments results in a loss of precision and accuracy and
     *   requires complex rounding rules to compensate for.
     *
     * ## Admin Considerations
     *
     * ### Global Settings
     *
     * This plugin adds two product measurements to the WooCommerce > Catalog
     * global configuration: area and volume.  Additionally a few new units are
     * added to the core Weight/Dimension measurements
     *
     * ### Product Configuration
     *
     * In the product edit screen a new tab named Measurement is added to the Product
     * Data panel.  This allows the measurement price calculator to be configured
     * for a given product, and the settings here can change other parts of the edit
     * product admin by changing labels, hiding fields, etc.
     *
     * An area and volume measurement field is added to the Shipping tab.
     *
     * ## Frontend
     *
     * ### Cart Item Data
     *
     * The following cart item data is added for pricing calculator products:
     *
     * pricing_item_meta_data => Array(
     *   _price                   => (float) the total product price,
     *   _measurement_needed      => (float) the total measurment needed,
     *   _measurement_needed_unit => (string) the total measurement units,
     *   _quantity                => (int) the quantity added by the customer,
     *   <measurement name>       => (float) measurement amount provided by the customer and depends on the calculator type.  For instance 'length' => 2
     * )
     *
     * ## Database
     *
     * ### Order Item Meta
     *
     * + `<measurement label> (<unit>)` - Visible measurement label and unit for
     *   the pricing calculator product measurements, with associated value supplied
     *   by the customer Ie: "Length (ft): 2"
     *
     * + `Total <measurement> (<unit>)` - Visble total measurement label and unit
     *   for the pricing calculator product measurements, with associated value supplied
     *   by the customer.  Ie: "Total Area (sq. ft.): 4"
     *
     * + `_measurement_data` - Serialized array of pricing calculator product
     *   measurements so that a customized product can be re-ordered:
     *   Array(
     *     <measurement name> => Array(
     *       value => (numeric) the value,
     *       unit  => (string) the unit,
     *     ),
     *     _measurement_needed      => (numeric) the total product measurement,
     *     _measurement_needed_unit => (string) the unit for _measurement_needed
     *   )
     *
     * TODO: after spending some time adding compatibility with various plugins (Dynamic Pricing, Product Addons, etc) consider rethinking the way we set the calculated price.
     *   Rather than setting it to the session, I think Dynamic Pricing adds it in after the cart is pulled from the session.  Which might make more sense?
     *
     * @since 1.0
     */
    class WC_Measurement_Price_Calculator extends SV_WC_Plugin
    {
        /** plugin version */
        const VERSION = '3.8.0';
        /** @var WC_Measurement_Price_Calculator single instance of this plugin */
        protected static $instance;
        /** the plugin id */
        const PLUGIN_ID = 'measurement_price_calculator';
        /** plugin text domain */
        const TEXT_DOMAIN = 'woocommerce-measurement-price-calculator';
        /**
         * The pricing calculator inventory handling class
         * @var WC_Price_Calculator_Inventory
         */
        private $pricing_calculator_inventory;
        /**
         * The pricing calculator cart class
         * @var WC_Price_Calculator_Cart
         */
        private $cart;
        /**
         * The pricing calculator frontend product loop class
         * @var WC_Price_Calculator_Product_loop
         */
        private $product_loop;
        /**
         * The pricing calculator frontend product page class
         * @var WC_Price_Calculator_Product_page
         */
        private $product_page;
        /**
         * The compatibility class
         * @var WC_Price_Calculator_Compatibility
         */
        private $compatibility;
        /**
         * Construct and initialize the main plugin class
         *
         * @see SV_WC_Plugin::__construct()
         */
        public function __construct()
        {
            parent::__construct(self::PLUGIN_ID, self::VERSION, self::TEXT_DOMAIN);
            // include required files
            $this->includes();
            add_action('woocommerce_init', array($this, 'woocommerce_init'));
            add_action('sv_wc_framework_plugins_loaded', array($this, 'init'));
        }
        /**
         * Handle localization, WPML compatible
         *
         * @see SV_WC_Plugin::load_translation()
         */
        public function load_translation()
        {
            // localization (remember symlinks will break this)
            load_plugin_textdomain('woocommerce-measurement-price-calculator', false, dirname(plugin_basename($this->get_file())) . '/i18n/languages');
        }
        /**
         * Init Measurement Price Calculator when WooCommerce initializes
         */
        public function woocommerce_init()
        {
            // include files which depend on WooCommerce being loaded
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-inventory.php';
            // inventory handling
            $this->pricing_calculator_inventory = new WC_Price_Calculator_Inventory();
            // frontend product loop handling
            $this->product_loop = new WC_Price_Calculator_Product_Loop();
            // frontend product page handling
            $this->product_page = new WC_Price_Calculator_Product_Page();
            // frontend cart handling
            $this->cart = new WC_Price_Calculator_Cart();
            // compatibility class
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-compatibility.php';
            $this->compatibility = new WC_Price_Calculator_Compatibility();
            // add pricing table shortcode
            add_shortcode('wc_measurement_price_calculator_pricing_table', array($this, 'pricing_table_shortcode'));
        }
        /**
         * Remove the requirement that stock amounts be integers
         *
         * @since 3.3
         */
        public function init()
        {
            // Stock amounts are *not* integers by default
            remove_filter('woocommerce_stock_amount', 'intval');
            // so let them be
            add_filter('woocommerce_stock_amount', 'floatval');
        }
        /** Shortcodes ******************************************************/
        /**
         * Pricing table shortcode: renders a table of product prices
         *
         * @since 3.0
         * @param array $atts associative array of shortcode parameters
         * @return string shortcode content
         */
        public function pricing_table_shortcode($atts)
        {
            require_once $this->get_plugin_path() . '/classes/shortcodes/class-wc-price-calculator-shortcode-pricing-table.php';
            return WC_Shortcodes::shortcode_wrapper(array('WC_Price_Calculator_Shortcode_Pricing_Table', 'output'), $atts, array('class' => 'wc-measurement-price-calculator'));
        }
        /** Helper methods ******************************************************/
        /**
         * Main Measurement Price Calculator Instance, ensures only one instance is/can be loaded
         *
         * @since 3.6.0
         * @see wc_measurement_price_calculator()
         * @return WC_Measurement_Price_Calculator
         */
        public static function instance()
        {
            if (is_null(self::$instance)) {
                self::$instance = new self();
            }
            return self::$instance;
        }
        /**
         * Include required files
         */
        private function includes()
        {
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-cart.php';
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-measurement.php';
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-product-loop.php';
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-product-page.php';
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-product.php';
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-settings.php';
            if (is_admin()) {
                $this->admin_includes();
            }
        }
        /**
         * Include required admin files
         */
        private function admin_includes()
        {
            require_once $this->get_plugin_path() . '/admin/woocommerce-measurement-price-calculator-admin-init.php';
            // Admin section
        }
        /** Getter methods ******************************************************/
        /**
         * Returns the plugin name, localized
         *
         * @since 3.3
         * @see SV_WC_Plugin::get_plugin_name()
         * @return string the plugin name
         */
        public function get_plugin_name()
        {
            return __('WooCommerce Measurement Price Calculator', self::TEXT_DOMAIN);
        }
        /**
         * Returns __FILE__
         *
         * @since 3.3
         * @see SV_WC_Plugin::get_file()
         * @return string the full path and filename of the plugin file
         */
        protected function get_file()
        {
            return __FILE__;
        }
        /**
         * Gets the plugin documentation url
         *
         * @since 3.3.0
         * @return string documentation URL
         */
        public function get_documentation_url()
        {
            return 'http://docs.woothemes.com/document/measurement-price-calculator/';
        }
        /**
         * Gets the plugin support URL
         *
         * @since 3.7.0
         * @see SV_WC_Plugin::get_support_url()
         * @return string
         */
        public function get_support_url()
        {
            return 'http://support.woothemes.com/';
        }
        /**
         * Gets the product page class instance if it's set
         *
         * @since 3.7.0
         * @return WC_Price_Calculator_Product_Page The product page class instance
         */
        public function get_product_page_instance()
        {
            return isset($this->product_page) ? $this->product_page : null;
        }
        /** Lifecycle methods ******************************************************/
        /**
         * Initial plugin install path.  Note that with version 3.3 of the plugin
         * the database version option name changed, so this also handles the case
         * of updating in that circumstance
         *
         * @since 3.3
         * @see SV_WC_Plugin::install()
         */
        protected function install()
        {
            global $wpdb;
            // check for a pre 3.3 version
            $legacy_version = get_option('wc_measurement_price_calculator_db_version');
            if (false !== $legacy_version) {
                // upgrade path from previous version, trash old version option
                delete_option('wc_measurement_price_calculator_db_version');
                // upgrade path
                $this->upgrade($legacy_version);
                // and we're done
                return;
            }
            // true install
            require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-settings.php';
            // set the default units for our custom measurement types
            add_option('woocommerce_area_unit', WC_Price_Calculator_Settings::DEFAULT_AREA);
            add_option('woocommerce_volume_unit', WC_Price_Calculator_Settings::DEFAULT_VOLUME);
            // Upgrade path from pre-versioned 1.x
            // get all old-style measurement price calculator products
            $rows = $wpdb->get_results("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key='_measurement_price_calculator'");
            foreach ($rows as $row) {
                if ($row->meta_value) {
                    // calculator is enabled
                    $product_custom_fields = get_post_custom($row->post_id);
                    // as long as the product doesn't also already have a new-style price calculator settings
                    if (!isset($product_custom_fields['_wc_price_calculator'][0]) || !$product_custom_fields['_wc_price_calculator'][0]) {
                        $settings = new WC_Price_Calculator_Settings();
                        $settings = $settings->get_raw_settings();
                        // we want the underlying raw settings array
                        switch ($row->meta_value) {
                            case 'dimensions':
                                $settings['calculator_type'] = 'dimension';
                                // the previous version of the plugin allowed this weird multi-dimension tied input thing,
                                //  I don't think anyone actually used it, and it didn't make much sense, so I'm not supporting
                                //  it any longer
                                if ('yes' == $product_custom_fields['_measurement_dimension_length'][0]) {
                                    $settings['dimension']['length']['enabled'] = 'yes';
                                    $settings['dimension']['length']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                    $settings['dimension']['length']['editable'] = $product_custom_fields['_measurement_dimension_length_editable'][0];
                                } elseif ('yes' == $product_custom_fields['_measurement_dimension_width'][0]) {
                                    $settings['dimension']['width']['enabled'] = 'yes';
                                    $settings['dimension']['width']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                    $settings['dimension']['width']['editable'] = $product_custom_fields['_measurement_dimension_width_editable'][0];
                                } elseif ('yes' == $product_custom_fields['_measurement_dimension_height'][0]) {
                                    $settings['dimension']['height']['enabled'] = 'yes';
                                    $settings['dimension']['height']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                    $settings['dimension']['height']['editable'] = $product_custom_fields['_measurement_dimension_height_editable'][0];
                                }
                                break;
                            case 'area':
                                $settings['calculator_type'] = 'area';
                                $settings['area']['area']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                $settings['area']['area']['editable'] = $product_custom_fields['_measurement_editable'][0];
                                break;
                            case 'volume':
                                $settings['calculator_type'] = 'volume';
                                $settings['volume']['volume']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                $settings['volume']['volume']['editable'] = $product_custom_fields['_measurement_editable'][0];
                                break;
                            case 'weight':
                                $settings['calculator_type'] = 'weight';
                                $settings['weight']['weight']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                $settings['weight']['weight']['editable'] = $product_custom_fields['_measurement_editable'][0];
                                break;
                            case 'walls':
                                $settings['calculator_type'] = 'wall-dimension';
                                $settings['wall-dimension']['length']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                $settings['wall-dimension']['width']['unit'] = $product_custom_fields['_measurement_display_unit'][0];
                                break;
                        }
                        update_post_meta($row->post_id, '_wc_price_calculator', $settings);
                    }
                }
            }
        }
        /**
         * Perform any version-related changes. Changes to custom db tables should be handled by the migrate() method
         *
         * @since 3.0
         * @see SV_WC_Plugin::upgrade()
         * @param int $installed_version the currently installed version of the plugin
         */
        protected function upgrade($installed_version)
        {
            if (version_compare($installed_version, "3.0", '<')) {
                global $wpdb;
                require_once $this->get_plugin_path() . '/classes/class-wc-price-calculator-settings.php';
                // updating 3.0: From 2.0 to 3.0, the '_wc_price_calculator'
                // product post meta calculator settings structure changed: 'calculator'
                // was added to the 'pricing' option
                $rows = $wpdb->get_results("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key='_wc_price_calculator'");
                foreach ($rows as $row) {
                    if ($row->meta_value) {
                        // calculator settings found
                        $settings = new WC_Price_Calculator_Settings();
                        $settings = $settings->set_raw_settings($row->meta_value);
                        // we want the updated underlying raw settings array
                        $updated = false;
                        foreach (WC_Price_Calculator_Settings::get_measurement_types() as $measurement_type) {
                            if (isset($settings[$measurement_type]['pricing']['enabled']) && 'yes' == $settings[$measurement_type]['pricing']['enabled']) {
                                // enable the pricing calculator in the new settings data structure
                                $settings[$measurement_type]['pricing']['calculator'] = array('enabled' => 'yes');
                                $updated = true;
                            }
                        }
                        if ($updated) {
                            update_post_meta($row->post_id, '_wc_price_calculator', $settings);
                        }
                    }
                }
            }
        }
    }
    //WC_Measurement_Price_Calculator
    /**
     * Returns the One True Instance of Measurement Price Calculator
     *
     * @since 3.6.0
     * @return WC_Measurement_Price_Calculator
     */
    function wc_measurement_price_calculator()
    {
        return WC_Measurement_Price_Calculator::instance();
    }
    /**
     * The WC_Measurement_Price_Calculator global object
     *
     * @deprecated 3.6.0
     * @name $wc_measurement_price_calculator
     * @global WC_Measurement_Price_Calculator $GLOBALS['wc_measurement_price_calculator']
     */
    $GLOBALS['wc_measurement_price_calculator'] = wc_measurement_price_calculator();
}
 /**
  * Render the price calculator on the product page
  *
  * @since 3.0
  */
 public function render_price_calculator()
 {
     global $product;
     // is the calculator enabled for this product?
     if (!$product || !WC_Price_Calculator_Product::calculator_enabled($product)) {
         return;
     }
     $settings = new WC_Price_Calculator_Settings($product);
     if (WC_Price_Calculator_Product::pricing_calculator_enabled($product)) {
         // Pricing calculator with custom dimensions and a price "per unit"
         // get the product total measurement (ie Area or Volume, etc)
         $product_measurement = WC_Price_Calculator_Product::get_product_measurement($product, $settings);
         $product_measurement->set_unit($settings->get_pricing_unit());
         // get the product measurements, get a measurement, and set the product total measurement common unit based on the measurements common unit
         $measurements = $settings->get_calculator_measurements();
         list($measurement) = $measurements;
         $product_measurement->set_common_unit($measurement->get_unit_common());
         // pricing calculator enabled, get the template
         wc_get_template('single-product/price-calculator.php', array('product_measurement' => $product_measurement, 'settings' => $settings, 'measurements' => $measurements), '', wc_measurement_price_calculator()->get_plugin_path() . '/templates/');
         // need an element to contain the price for simple pricing rule products
         if ($product->is_type('simple') && $settings->pricing_rules_enabled()) {
             echo '<div class="single_variation"></div>';
         }
     } else {
         // quantity calculator.  where the quantity of product needed is based on the configured product dimensions.  This is a actually bit more complex
         // get the starting quantity, max quantity, and total product measurement in product units
         $quantity_range = WC_Price_Calculator_Product::get_quantity_range($product);
         // set the product measurement based on the minimum quantity value, and set the unit to the frontend calculator unit
         $measurements = $settings->get_calculator_measurements();
         // The product measurement will be used to create the 'amount actual' field.
         $product_measurement = WC_Price_Calculator_Product::get_product_measurement($product, $settings);
         // see whether all calculator measurements are defined in the same units (ie 'in', 'sq. in.' are considered the same)
         $measurements_unit = null;
         foreach ($measurements as $measurement) {
             if (!$measurements_unit) {
                 $measurements_unit = $measurement->get_unit();
             } else {
                 if (!WC_Price_Calculator_Measurement::compare_units($measurements_unit, $measurement->get_unit())) {
                     $measurements_unit = false;
                     break;
                 }
             }
         }
         // All calculator measurements use the same base units, so lets use those for the 'amount actual' field
         //  area/volume product measurement can have a calculator measurement defined in units of length, so it
         //  will need to be converted to units of area or volume respectively
         if ($measurements_unit) {
             switch ($product_measurement->get_type()) {
                 case 'area':
                     $measurements_unit = WC_Price_Calculator_Measurement::to_area_unit($measurements_unit);
                     break;
                 case 'volume':
                     $measurements_unit = WC_Price_Calculator_Measurement::to_volume_unit($measurements_unit);
                     break;
             }
         }
         // if the price per unit is displayed for this product, default to the pricing units for the 'amount actual' field
         if (WC_Price_Calculator_Product::pricing_per_unit_enabled($product)) {
             $measurements_unit = $settings->get_pricing_unit();
         }
         // if a measurement unit other than the default was determined, set it
         if ($measurements_unit) {
             $product_measurement->set_unit($measurements_unit);
         }
         $total_price = '';
         if ($product->is_type('simple')) {
             // If the product type is simple we can set an initial 'Amount Actual' and 'total price'
             //  we can't do this for variable products because we don't know which will be configured
             //  initially (actually I guess a default product can be configured, so maybe we can do something here)
             // not enough product physical attributes defined to get our measurement, so bail
             if (!$product_measurement->get_value()) {
                 return;
             }
             // figure out the starting measurement amount
             // multiply the starting quantity by the measurement value
             $product_measurement->set_value(round($quantity_range['min_value'] * $product_measurement->get_value(), 2));
             $total_price = wc_price($quantity_range['min_value'] * WC_Price_Calculator_Compatibility::get_product_display_price($product), 2);
         } elseif ($product->is_type('variable')) {
             // clear the product measurement value for variable products, since we can't really know what it is ahead of time (except for when a default is set)
             $product_measurement->set_value('');
         }
         // pricing calculator enabled, get the template
         wc_get_template('single-product/quantity-calculator.php', array('calculator_type' => $settings->get_calculator_type(), 'product_measurement' => $product_measurement, 'measurements' => $measurements, 'total_price' => $total_price), '', wc_measurement_price_calculator()->get_plugin_path() . '/templates/');
     }
 }
Beispiel #6
0
 * @author    SkyVerge
 * @copyright Copyright (c) 2012-2015, SkyVerge, Inc.
 * @license   http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
 */
/**
 * WooCommerce Measurement Price Calculator Write Panels
 *
 * Sets up the write panels used by the measurement price calculator plugin
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
include_once wc_measurement_price_calculator()->get_plugin_path() . '/admin/post-types/writepanels/writepanel-product_data.php';
include_once wc_measurement_price_calculator()->get_plugin_path() . '/admin/post-types/writepanels/writepanel-product_data-calculator.php';
include_once wc_measurement_price_calculator()->get_plugin_path() . '/admin/post-types/writepanels/writepanel-product-type-variable.php';
/**
 * Returns the WooCommerce product settings, containing measurement units
 *
 * @since 3.3
 */
function wc_measurement_price_calculator_get_wc_settings()
{
    include_once WC()->plugin_path() . '/includes/admin/settings/class-wc-settings-page.php';
    $settings_products = (include WC()->plugin_path() . '/includes/admin/settings/class-wc-settings-products.php');
    return $settings_products->get_settings();
}
/**
 * Returns all available weight units
 *
 * @since 3.0