product details
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_Linked_Packages
|
||||
*/
|
||||
|
||||
class Wiaas_Admin_Linked_Packages {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'wp_ajax_wiaas_json_search_addons', array(__CLASS__, 'json_search_addons') );
|
||||
add_action( 'wp_ajax_wiaas_json_search_options', array(__CLASS__, 'json_search_options') );
|
||||
|
||||
add_action( 'wp_ajax_wiaas_create_empty_option_group', array(__CLASS__, 'create_empty_option_group') );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects default woocommerce linked packages tab to wiaas linked packages tab
|
||||
* @param $tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'linked_product' ]['label'] = __( 'Linked Packages', 'wiaas' );
|
||||
$tabs[ 'linked_product' ]['target'] = 'wiaas_linked_packages';
|
||||
$tabs[ 'linked_product' ]['class'] = array('show_if_bundle', 'hide_if_simple');
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders wiaas linked packages tab
|
||||
*/
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
|
||||
$package = wc_get_product( $post->ID );
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
$option_groups = Wiaas_Package_Option_Groups::get_package_option_groups($package);
|
||||
|
||||
include 'views/html-linked-packages.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements ajax search for package addons
|
||||
*/
|
||||
public static function json_search_addons() {
|
||||
self::_json_search_packages('add_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements ajax searc for package options
|
||||
*/
|
||||
public static function json_search_options() {
|
||||
|
||||
self::_json_search_packages('option');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and renders new optional packages group
|
||||
*/
|
||||
public static function create_empty_option_group() {
|
||||
$group = array(
|
||||
'name' => 'Untitled',
|
||||
'id' => uniqid('option_'),
|
||||
'default' => false,
|
||||
'options' => array()
|
||||
);
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
||||
</script>
|
||||
<?php
|
||||
$group_options = isset($group['options']) ? $group['options'] : array();
|
||||
$id = $group['id'];
|
||||
|
||||
include 'views/html-package-options-group.php';
|
||||
?>
|
||||
<?php
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves posted linked packages data
|
||||
*
|
||||
* @param $package_id
|
||||
*/
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
// Handle linked addons
|
||||
|
||||
$addons_ids = isset( $_POST['wiaas_addon_packages'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $_POST['wiaas_addon_packages'] ) ) :
|
||||
array();
|
||||
|
||||
Wiaas_Package_Addon::set_package_addons(
|
||||
$package,
|
||||
$addons_ids);
|
||||
|
||||
// Handle linked options
|
||||
|
||||
$posted_option_groups = isset( $_POST['wiaas_option_groups'] ) ? $_POST['wiaas_option_groups'] : array();
|
||||
|
||||
$option_groups = array();
|
||||
|
||||
foreach ($posted_option_groups as $id => $posted_option_group) {
|
||||
$option_group = array(
|
||||
'id' => $posted_option_group['id'],
|
||||
'name' => $posted_option_group['name'],
|
||||
'default' => $posted_option_group['default'],
|
||||
'options' => array()
|
||||
);
|
||||
$option_group['options'] = isset( $posted_option_group['options'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $posted_option_group['options'] ) ) :
|
||||
array();
|
||||
|
||||
$option_groups[] = $option_group;
|
||||
}
|
||||
|
||||
Wiaas_Package_Option_Groups::set_package_option_groups(
|
||||
$package,
|
||||
$posted_option_groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements search for packages of provided type
|
||||
* @param $package_type
|
||||
*/
|
||||
private static function _json_search_packages($package_type) {
|
||||
check_ajax_referer( 'search-products', 'security' );
|
||||
|
||||
$term = wc_clean( empty( $term ) ? wp_unslash( $_GET['term'] ) : $term );
|
||||
|
||||
if ( empty( $term ) ) {
|
||||
wp_die();
|
||||
}
|
||||
|
||||
$data_store = WC_Data_Store::load( 'product' );
|
||||
$ids = $data_store->search_products( $term );
|
||||
|
||||
$packages= array_filter( array_map( 'wc_get_product', $ids ), 'wc_products_array_filter_readable' );
|
||||
$result = array();
|
||||
|
||||
foreach ( $packages as $package ) {
|
||||
|
||||
if (Wiaas_Package_Type::get_package_type($package->get_id()) === $package_type) {
|
||||
$result[ $package->get_id() ] = rawurldecode( $package->get_formatted_name() );
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json( $result );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Linked_Packages::init();
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Package_Addon {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_addons' ] = array(
|
||||
'label' => __( 'Add-ons', 'wiaas' ),
|
||||
'target' => 'wiaas_package_addons',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_addons" class="panel woocommerce_options_panel wc_gte_30">
|
||||
<div class="options_group">
|
||||
<p class="form-field">
|
||||
<label for="wiaas_addon_packages"><?php esc_html_e( 'Additional packages:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
id="wiaas_addon_packages"
|
||||
name="wiaas_addon_packages[]"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for a product…', 'wiaas' ); ?>"
|
||||
data-action="woocommerce_json_search_products"
|
||||
data-exclude="<?php echo intval( $package->get_id() ); ?>">
|
||||
<?php
|
||||
foreach ( $addons as $addon ) {
|
||||
echo '<option value="' . esc_attr( $addon->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $addon->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php echo wc_help_tip( __( 'This lets you choose which packages will be available as addons.', 'wiaas' ) );?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function meta_box_javascript() {
|
||||
|
||||
}
|
||||
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$addons_ids = isset( $_POST['wiaas_addon_packages'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $_POST['wiaas_addon_packages'] ) ) :
|
||||
array();
|
||||
|
||||
Wiaas_Package_Addon::set_package_addons(
|
||||
$package,
|
||||
$addons_ids);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Addon::init();
|
||||
@@ -1,242 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Package_Option_Groups {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'wp_ajax_wiaas_create_empty_option_group', array(__CLASS__, 'create_empty_option_group') );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
public static function create_empty_option_group() {
|
||||
$option_group = array(
|
||||
'name' => 'Untitled',
|
||||
'id' => uniqid('option_'),
|
||||
'default' => false,
|
||||
'options' => array()
|
||||
);
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
||||
</script>
|
||||
<?php
|
||||
self::_render_option_group($option_group);
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_options_groups' ] = array(
|
||||
'label' => __( 'Option groups', 'wiaas' ),
|
||||
'target' => 'wiaas_package_option_groups',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
|
||||
$option_groups = Wiaas_Package_Option_Groups::get_package_option_groups($package);
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_option_groups" class="panel wc-metaboxes-wrapper hidden">
|
||||
<?php self::meta_box_javascript(); ?>
|
||||
<div class="toolbar toolbar-top">
|
||||
<button type="button" class="button button-primary" id="wiaas_add_option_group">
|
||||
<?php esc_html_e( 'Add new option group', 'wiaas' ); ?>
|
||||
</button>
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all"><?php esc_html_e( 'Expand', 'wiaas' ); ?></a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
<div id="wiaas_package_option_groups_list" class="wc-metaboxes">
|
||||
<?php
|
||||
foreach ($option_groups as $option_group) {
|
||||
self::_render_option_group($option_group);
|
||||
}
|
||||
// render empty option group
|
||||
?>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all">
|
||||
<?php esc_html_e( 'Expand', 'wiaas' ); ?>
|
||||
</a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_option_group($group) {
|
||||
$group_options = isset($group['options']) ? $group['options'] : array();
|
||||
$id = $group['id'];
|
||||
|
||||
?>
|
||||
<div id="wiaas_option_group_<?php echo esc_attr( $id ); ?>" class="wc-metabox closed">
|
||||
<h3>
|
||||
<a
|
||||
href="#"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="delete delete_wiaas_option_group">
|
||||
<?php esc_html_e( 'Remove', 'wiaas' ); ?>
|
||||
</a>
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'wiaas' ); ?>"></div>
|
||||
<strong id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_title">
|
||||
<?php echo $group['name']; ?>
|
||||
</strong>
|
||||
</h3>
|
||||
<div class="wc-metabox-content">
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<label><?php esc_html_e( 'Name', 'wiaas' ); ?>:</label>
|
||||
<input
|
||||
type="text"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="wiaas_option_group_name"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][name]"
|
||||
value="<?php echo esc_attr( $group['name'] ); ?>" />
|
||||
<input
|
||||
type="hidden"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][id]"
|
||||
value="<?php echo esc_attr( $id ); ?>" />
|
||||
</td>
|
||||
<td rowspan="3">
|
||||
<label><?php esc_html_e( 'Options:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][options][]"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for a product…', 'wiaas' ); ?>"
|
||||
data-action="woocommerce_json_search_products"
|
||||
data-exclude="">
|
||||
<?php
|
||||
foreach ( $group_options as $group_option ) {
|
||||
echo '<option value="' . esc_attr( $group_option->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $group_option->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="checkbox wiaas_option_group_default"
|
||||
<?php checked( $group['default'], true ); ?>
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][default]"
|
||||
value="1" />
|
||||
<?php esc_html_e( 'Set as default', 'wiaas' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function meta_box_javascript() {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas_add_option_group").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var data = {
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'wiaas_create_empty_option_group'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_option_groups_list').append(response);
|
||||
});
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.delete_wiaas_option_group', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this option group?', 'wiaas' ); ?>")) {
|
||||
var id = $(this).data('id');
|
||||
$('#wiaas_option_group_' + id).slideUp().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_name', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var name = $(this).val();
|
||||
var id = $(this).data('id');
|
||||
|
||||
$(`#wiaas_option_group_${id}_title`).text(name);
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_default', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var id = $(this).data('id');
|
||||
|
||||
$(`:input.wiaas_option_group_default`).each(function() {
|
||||
var group_id = $(this).data('id');
|
||||
if (group_id !== id) {
|
||||
$(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$posted_option_groups = isset( $_POST['wiaas_option_groups'] ) ? $_POST['wiaas_option_groups'] : array();
|
||||
|
||||
error_log(print_r($posted_option_groups, true));
|
||||
|
||||
$option_groups = array();
|
||||
|
||||
foreach ($posted_option_groups as $id => $posted_option_group) {
|
||||
$option_group = array(
|
||||
'id' => $posted_option_group['id'],
|
||||
'name' => $posted_option_group['name'],
|
||||
'default' => $posted_option_group['default'],
|
||||
'options' => array()
|
||||
);
|
||||
$option_group['options'] = isset( $posted_option_group['options'] ) ?
|
||||
array_filter( array_map( 'intval', (array) $posted_option_group['options'] ) ) :
|
||||
array();
|
||||
|
||||
$option_groups[] = $option_group;
|
||||
}
|
||||
|
||||
Wiaas_Package_Option_Groups::set_package_option_groups(
|
||||
$package,
|
||||
$posted_option_groups);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Option_Groups::init();
|
||||
@@ -1,356 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Package_Pricing
|
||||
*/
|
||||
class Wiaas_Admin_Package_Pricing {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
add_action( 'wp_ajax_create_empty_pricing_rule', array(__CLASS__, 'create_empty_pricing_rule') );
|
||||
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ), 1, 2 );
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
||||
}
|
||||
|
||||
public static function create_empty_pricing_rule() {
|
||||
$pay_type = $_POST['pay_type'];
|
||||
$pricing_rule_sets = array();
|
||||
$pricing_rule_sets[ $pay_type ] = Wiaas_Package_Pricing::get_empty_pricing_rule();
|
||||
self::_render_pricing_rules( $pricing_rule_sets );
|
||||
}
|
||||
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_price' ] = array(
|
||||
'label' => __( 'Pricing', 'wiaas' ),
|
||||
'target' => 'wiaas_package_price',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public static function package_data_panel() {
|
||||
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_price" class="panel woocommerce_options_panel wc_gte_30">
|
||||
<div id="wiaas_package_pricing_rules" data-setindex="<?php echo count( $pricing_rules ); ?>">
|
||||
<?php self::meta_box_javascript(); ?>
|
||||
<?php self::_render_pricing_rules( $pricing_rules ); ?>
|
||||
</div>
|
||||
<?php self::_render_pricing_controls( $pricing_rules ); ?>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_pricing_rules( $pricing_rule_sets ) {
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ( $pricing_rule_sets as $name => $pricing_rule_set ) {
|
||||
$pay_type = $available_pay_types[$name];
|
||||
?>
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule">
|
||||
<div class="section">
|
||||
<h4 class="first"><?php echo $pay_type['title']; ?>
|
||||
<a href="#" data-name="<?php echo $name; ?>"
|
||||
class="delete_wiaas_pricing_rule">
|
||||
REMOVE
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( 'Minimal fixed price:', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="wiaas_minimal_fixed_price_<?php echo $name; ?>"
|
||||
data-name="<?php echo $name; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][minimal_fixed_price]"
|
||||
value="<?php echo $pricing_rule_set['minimal_fixed_price'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php self::_render_pricing_rule_recurrent_price($name, $pay_type, $pricing_rule_set) ?>
|
||||
<?php self::_render_pricing_rule_principal_amount($name, $pay_type, $pricing_rule_set) ?>
|
||||
<?php self::_render_pricing_rule_services_price($name, $pay_type, $pricing_rule_set) ?>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( 'Max contract period:', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span id="wiaas_max_contract_period_<?php echo $name; ?>">
|
||||
<?php echo $pay_type['max_contract_period'] . ' ' . $pay_type['period_unit'] ?>
|
||||
</span>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private static function _render_pricing_rule_services_price($name, $pay_type, $pricing_rule) {
|
||||
$label = 'Minimal services and support price ';
|
||||
if ($pay_type['services_contract_period'] > 0) {
|
||||
$label .= '(' . $pay_type['services_contract_period'] . ' ' . $pay_type['period_unit'] . ')';
|
||||
} else {
|
||||
$label .= '(Unbound)';
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td class="wiaas_label_container">
|
||||
<?php _e( $label . ':', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td class="wiaas_input_container">
|
||||
<input
|
||||
id="wiaas_minimal_services_price_<?php echo $name; ?>"
|
||||
class="wiaas_minimal_services_price"
|
||||
data-name="<?php echo $name; ?>"
|
||||
data-period="<?php echo $pay_type['services_contract_period']; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][minimal_services_price]"
|
||||
value="<?php echo $pricing_rule['minimal_services_price'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td>
|
||||
<span style="line-height: 28px; margin-left: 10px;">
|
||||
<?php echo ' / ' . $pay_type['period_unit'] ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
if ($pay_type['services_contract_period'] > 0) {
|
||||
?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>Final total:</td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_services_price_<?php echo $name; ?>_final">
|
||||
<?php echo round(
|
||||
$pricing_rule['minimal_services_price'] * $pay_type['services_contract_period'],
|
||||
2) ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private static function _render_pricing_rule_principal_amount($name, $pay_type, $pricing_rule) {
|
||||
if ($pay_type['package_pay_period'] === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value_per_month = round($pricing_rule['principal_amount'] / $pay_type['package_pay_period'], 2);
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php _e( 'Principal amount:', 'wiaas' ); ?></td>
|
||||
<td class="wiaas_input_container">
|
||||
<input
|
||||
id="wiaas_principal_amount_<?php echo $name; ?>"
|
||||
class="wiaas_principal_amount"
|
||||
data-name="<?php echo $name; ?>"
|
||||
data-period="<?php echo $pay_type['package_pay_period']; ?>"
|
||||
name="wiaas_pricing_rules[<?php echo $name; ?>][principal_amount]"
|
||||
value="<?php echo $pricing_rule['principal_amount'] ?>"
|
||||
type="text" />
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<?php _e( 'Minimal recurrent package price ( ' .
|
||||
$pay_type['services_contract_period'] .
|
||||
' ' . $pay_type['period_unit'] .
|
||||
'): ', 'wiaas' ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_recurrent_package_price_<?php echo $name; ?>">
|
||||
<?php echo $value_per_month ?>
|
||||
</span>
|
||||
<?php echo ' / ' . $pay_type['period_unit'] ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_pricing_rule_recurrent_price($name, $pay_type, $pricing_rule) {
|
||||
$value = $pricing_rule['minimal_services_price'];
|
||||
if ($pricing_rule['principal_amount'] > 0 && $pay_type['package_pay_period'] > 0) {
|
||||
$value += $pricing_rule['principal_amount'] / $pay_type['package_pay_period'];
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php _e( 'Minimal recurrent price:', 'wiaas' ); ?></td>
|
||||
<td>
|
||||
<span id="wiaas_minimal_recurrent_price_<?php echo $name; ?>">
|
||||
<?php echo round($value, 2) ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function _render_pricing_controls($pricing_rule_sets) {
|
||||
$has_available_pay_types = false;
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
if (!isset($pricing_rule_sets[$name])) {
|
||||
$has_available_pay_types = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$class = $has_available_pay_types ? '' : 'wiaas_hidden';
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_price_controls" class="section <?php echo $class ?>">
|
||||
<select id="wiaas_pay_type" name="wiaas-pay-type" class="pricing_rule_mode">
|
||||
<?php
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
?>
|
||||
<option
|
||||
value="<?php echo $name ?>"
|
||||
id="wiaas_pay_type_<?php echo $name ?>"
|
||||
class="<?php echo $class ?>"
|
||||
>
|
||||
<?php _e( $pay_type['title'], 'wiaas' ); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button
|
||||
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
|
||||
id="wiaas-add-pricing"
|
||||
type="button"
|
||||
class="button button-primary">
|
||||
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function meta_box_javascript() {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas-add-pricing").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
|
||||
$("#wiaas_package_pricing_rules").data('setindex', set_index);
|
||||
|
||||
var pay_type = $('#wiaas_pay_type').val();
|
||||
|
||||
var data = {
|
||||
'pay_type': pay_type,
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'create_empty_pricing_rule'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_pricing_rules').append(response);
|
||||
|
||||
$(`#wiaas_pay_type_${pay_type}`).addClass('wiaas_hidden');
|
||||
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 0) {
|
||||
$('#wiaas_package_price_controls').addClass('wiaas_hidden');
|
||||
} else {
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//Remove Pricing Type
|
||||
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this pay type?', 'wiaas' ); ?>")) {
|
||||
var name = $(this).data('name');
|
||||
$('#wiaas-pricing-rule-' + name).slideUp().remove();
|
||||
|
||||
// append new option to controls
|
||||
$(`#wiaas_pay_type_${name}`).removeClass('wiaas_hidden');
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 1) {
|
||||
$('#wiaas_package_price_controls').removeClass('wiaas_hidden');
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var minimal_services_price = parseFloat($(this).val()) || 0;
|
||||
var principal_amount = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
|
||||
if (principal_amount_input) {
|
||||
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
|
||||
}
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
|
||||
var services_contract_period = $(this).data('period');
|
||||
if (services_contract_period > 0) {
|
||||
var final_services_price = minimal_services_price * services_contract_period;
|
||||
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var principal_amount = parseFloat($(this).val() / $(this).data('period')) || 0;
|
||||
var minimal_services_price = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
|
||||
if (minimal_services_price_input) {
|
||||
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
|
||||
}
|
||||
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(2));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function process_meta_box( $post_id, $post ) {
|
||||
Wiaas_Package_Pricing::set_package_prices(
|
||||
wc_get_product( $post_id ),
|
||||
$_POST['wiaas_pricing_rules']);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Pricing::init();
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_Package_Types
|
||||
*/
|
||||
class Wiaas_Admin_Package_Types {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'woocommerce_product_options_general_product_data', array( __CLASS__, 'package_types_data' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders wiaas package types options
|
||||
*/
|
||||
public static function package_types_data() {
|
||||
|
||||
global $post;
|
||||
|
||||
$package = wc_get_product( $post->ID );
|
||||
|
||||
include 'views/html-package-types.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves posted wiaas package type data
|
||||
* @param $package_id
|
||||
*/
|
||||
public static function process_meta_box($package_id) {
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
if ($package->get_type() === 'bundle') {
|
||||
// Save wiaas package type
|
||||
Wiaas_Package_Type::set_package_type($package_id, $_POST['wiaas_package_type']);
|
||||
} else {
|
||||
Wiaas_Package_Type::set_package_type($package_id, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package_Types::init();
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas Linked Packages Editor
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_linked_packages" class="panel woocommerce_options_panel">
|
||||
|
||||
<div class="options_group">
|
||||
<p class="form-field">
|
||||
<label style="font-weight: bold;" for="wiaas_addon_packages"><?php esc_html_e( 'Add-ons:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
id="wiaas_addon_packages"
|
||||
name="wiaas_addon_packages[]"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for addons ...', 'wiaas' ); ?>"
|
||||
data-action="wiaas_json_search_addons"
|
||||
data-exclude="<?php echo intval( $package->get_id() ); ?>">
|
||||
<?php
|
||||
foreach ( $addons as $addon ) {
|
||||
echo '<option value="' . esc_attr( $addon->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $addon->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php echo wc_help_tip( __( 'This lets you choose which packages will be available as addons.', 'wiaas' ) );?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas_add_option_group").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var data = {
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'wiaas_create_empty_option_group'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_option_groups_list').append(response);
|
||||
});
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.delete_wiaas_option_group', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this option group?', 'wiaas' ); ?>")) {
|
||||
var id = $(this).data('id');
|
||||
$('#wiaas_option_group_' + id).slideUp().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_name', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var name = $(this).val();
|
||||
var id = $(this).data('id');
|
||||
|
||||
$(`#wiaas_option_group_${id}_title`).text(name);
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_option_groups').delegate('.wiaas_option_group_options', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var id = $(this).data('id');
|
||||
var selected_options_ids = $(this).val() ? $(this).val().toString().split(',') : [];
|
||||
var previous_options_ids = $(this).data('selected') ? $(this).data('selected').toString().split(',') : [];
|
||||
|
||||
var added_option_id = selected_options_ids.find(id => previous_options_ids.indexOf(id) === -1);
|
||||
var removed_option_id = previous_options_ids.find(id => selected_options_ids.indexOf(id) === -1);
|
||||
|
||||
if (added_option_id) {
|
||||
$(this).children().filter(function() {
|
||||
var option_id = $(this).val();
|
||||
return option_id === added_option_id;
|
||||
}).clone().appendTo(`#wiaas_option_group_${id}_default`);
|
||||
}
|
||||
|
||||
if (removed_option_id) {
|
||||
$(`#wiaas_option_group_${id}_default`).children().
|
||||
filter(function() {
|
||||
var option_id = $(this).val();
|
||||
return option_id === removed_option_id;
|
||||
}).
|
||||
remove();
|
||||
}
|
||||
|
||||
$(this).data('selected', selected_options_ids.join(','));
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="wiaas_package_option_groups" class="wc-metaboxes-wrapper">
|
||||
<div class="toolbar toolbar-top">
|
||||
<button type="button" class="button button-primary" id="wiaas_add_option_group">
|
||||
<?php esc_html_e( 'Add new option group', 'wiaas' ); ?>
|
||||
</button>
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all"><?php esc_html_e( 'Expand', 'wiaas' ); ?></a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
<div id="wiaas_package_option_groups_list" class="wc-metaboxes">
|
||||
<?php
|
||||
foreach ($option_groups as $group) {
|
||||
$group_options = isset($group['options']) ? $group['options'] : array();
|
||||
$id = $group['id'];
|
||||
|
||||
include 'html-package-options-group.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<span class="expand-close">
|
||||
<a href="#" class="expand_all">
|
||||
<?php esc_html_e( 'Expand', 'wiaas' ); ?>
|
||||
</a>
|
||||
/
|
||||
<a href="#" class="close_all"><?php esc_html_e( 'Close', 'wiaas' ); ?></a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas Package Option Group Editor
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_option_group_<?php echo esc_attr( $id ); ?>" class="wiaas_option_group wc-metabox closed">
|
||||
<h3>
|
||||
<a
|
||||
href="#"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="delete delete_wiaas_option_group">
|
||||
<?php esc_html_e( 'Remove', 'wiaas' ); ?>
|
||||
</a>
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'wiaas' ); ?>"></div>
|
||||
<strong id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_title">
|
||||
<?php echo $group['name']; ?>
|
||||
</strong>
|
||||
</h3>
|
||||
<div class="wc-metabox-content">
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<label><?php esc_html_e( 'Name', 'wiaas' ); ?>:</label>
|
||||
<input
|
||||
type="text"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
class="wiaas_option_group_name"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][name]"
|
||||
value="<?php echo esc_attr( $group['name'] ); ?>" />
|
||||
<input
|
||||
type="hidden"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][id]"
|
||||
value="<?php echo esc_attr( $id ); ?>" />
|
||||
</td>
|
||||
<td rowspan="3">
|
||||
<label><?php esc_html_e( 'Options:', 'wiaas' ); ?></label>
|
||||
<select
|
||||
class="wc-product-search wiaas_option_group_options"
|
||||
multiple="multiple"
|
||||
style="width: 50%;"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][options][]"
|
||||
data-id="<?php echo esc_attr( $id ); ?>"
|
||||
data-sortable="true"
|
||||
data-placeholder="<?php esc_attr_e( 'Search for options ...', 'wiaas' ); ?>"
|
||||
data-action="wiaas_json_search_options"
|
||||
data-selected="<?php echo implode( ',', array_map(function($option) { return $option->get_id(); }, $group_options)) ?>"
|
||||
data-exclude="">
|
||||
<?php
|
||||
foreach ( $group_options as $option ) {
|
||||
echo '<option value="' . esc_attr( $option->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $option->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<?php esc_html_e( 'Default option:', 'wiaas' ); ?>
|
||||
</label>
|
||||
<select
|
||||
id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_default"
|
||||
name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][default]"
|
||||
>
|
||||
<?php
|
||||
foreach ( $group_options as $option ) {
|
||||
echo '<option value="' . esc_attr( $option->get_id() ) . '"' .
|
||||
selected( $option->get_id(), $group['default'], false ) .
|
||||
'>' .
|
||||
wp_kses_post( $option->get_formatted_name() ) .
|
||||
'</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas Package Types Editor
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_package_type_editor" class="options_group show_if_bundle hidden">
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas_package_type").change(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
handlePackageTypeToolsVisiblity();
|
||||
});
|
||||
|
||||
function handlePackageTypeToolsVisiblity() {
|
||||
var currentPackageType = $('#wiaas_package_type').val();
|
||||
var productType = $('#product-type').val();
|
||||
|
||||
if (currentPackageType === 'standard' && productType === 'bundle') {
|
||||
$('#woocommerce-product-data').find('.linked_product_tab').show();
|
||||
} else {
|
||||
$('#woocommerce-product-data').find('.linked_product_tab').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function showDownloadableFiles() {
|
||||
$('#general_product_data').find('.show_if_downloadable').each(function() {
|
||||
$(this).show();
|
||||
$(this).removeClass('hidden');
|
||||
$(this).removeClass('show_if_downloadable');
|
||||
|
||||
$(this).find('._download_limit_field, ._download_expiry_field').hide();
|
||||
});
|
||||
}
|
||||
|
||||
showDownloadableFiles();
|
||||
|
||||
handlePackageTypeToolsVisiblity();
|
||||
});
|
||||
</script>
|
||||
|
||||
<p class="form-field">
|
||||
<label for="wiaas_package_type"><?php esc_html_e( 'Package type:', 'wiaas' ); ?></label>
|
||||
<select id="wiaas_package_type" name="wiaas_package_type">
|
||||
<?php
|
||||
// Array of available package types
|
||||
$package_types = Wiaas_Package_Type::get_available_package_types();
|
||||
|
||||
$current_package_type = Wiaas_Package_Type::get_package_type($package->get_id());
|
||||
$current_package_type = isset($current_package_type) ? $current_package_type : 'standard';
|
||||
|
||||
if ( ! empty( $package_types ) ) {
|
||||
foreach ( $package_types as $package_type ) {
|
||||
$label = '';
|
||||
switch($package_type) {
|
||||
case 'standard':
|
||||
$label = 'Standard';
|
||||
break;
|
||||
case 'option':
|
||||
$label = 'Option';
|
||||
break;
|
||||
case 'add_on':
|
||||
$label = 'Add-on';
|
||||
break;
|
||||
}
|
||||
|
||||
echo '<option ' .
|
||||
'value="' . esc_attr( $package_type ) . '" ' .
|
||||
selected( $package_type, $current_package_type, false ) .
|
||||
' >' .
|
||||
esc_html( $label ) .
|
||||
'</option>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php echo wc_help_tip( __( 'Choose Wiaas package type.', 'wiaas' ) );?>
|
||||
</p>
|
||||
</div>
|
||||
Reference in New Issue
Block a user