Admin Settings in all CPTs are already set. Continue to frontend.
This commit is contained in:
@@ -841,10 +841,13 @@ class Form {
|
||||
$last_cart_behavior = array_key_last($cart_behavior);
|
||||
$cart_behavior[$last_cart_behavior]['group'] = 'ended';
|
||||
|
||||
$global_currencies = get_global_currency_array();
|
||||
$default_currency = formipay_default_currency();
|
||||
|
||||
$cart_items = [
|
||||
'cart_items_group' => [
|
||||
'type' => 'group_title',
|
||||
'label' => __( 'Cart Items', 'formipay' ),
|
||||
'label' => __( 'Additional Order Items', 'formipay' ),
|
||||
'group' => 'started',
|
||||
'description' => __( 'Add static product or custom item to form as default and non-editable item in order items.', 'formipay' )
|
||||
],
|
||||
@@ -852,11 +855,12 @@ class Form {
|
||||
'type' => 'autocomplete',
|
||||
'post_type' => ['formipay-product'],
|
||||
'label' => __( 'Assign Product', 'formipay' ),
|
||||
'description' => __( 'Selected products will added to the order items automatically.', 'formipay' )
|
||||
'description' => __( 'Selected products will be added to the order items automatically, even if it is not added to cart.', 'formipay' )
|
||||
],
|
||||
'static_items' => [
|
||||
'type' => 'repeater',
|
||||
'label' => __( 'Assign Items', 'formipay' ),
|
||||
'label' => __( 'Static Items', 'formipay' ),
|
||||
'description' => __( 'Static items will behave like fee that will affect to order calculation but nothing will be delivered.', 'formipay' ),
|
||||
'fields' => [
|
||||
'label' => [
|
||||
'type' => 'text',
|
||||
@@ -870,16 +874,46 @@ class Form {
|
||||
'value' => 1,
|
||||
'required' => true
|
||||
],
|
||||
'amount' => [
|
||||
'type' => 'number',
|
||||
'label' => __( 'Item Amount', 'formipay' ),
|
||||
'description' => __( 'Will be calculated to item quantity', 'formipay' ),
|
||||
'required' => true
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
foreach($global_currencies as $currency){
|
||||
$default_currency_symbol = formipay_get_currency_data_by_value($default_currency, 'symbol');
|
||||
$currency_symbol = formipay_get_currency_data_by_value($currency['currency'], 'symbol');
|
||||
$currency_title = ucwords(formipay_get_currency_data_by_value($currency['currency'], 'title'));
|
||||
$decimal_digits = intval($currency['decimal_digits']);
|
||||
$step = $decimal_digits * 10;
|
||||
$step = $step > 0 ? 1 / $step : 1;
|
||||
$cart_items['static_items']['fields']['amount_'.$currency_symbol] = [
|
||||
'type' => 'number',
|
||||
'step' => $step,
|
||||
'min' => 0,
|
||||
'label' => __( 'Item Price in '.$currency_symbol, 'formipay' ),
|
||||
'description' => __( 'Will be calculated to item quantity', 'formipay' ),
|
||||
'placeholder' => __( 'Auto', 'formipay' )
|
||||
];
|
||||
|
||||
if(count($global_currencies) > 1){
|
||||
if($default_currency_symbol === $currency_symbol){
|
||||
$cart_items['static_items']['fields']['amount_'.$currency_symbol]['description'] = sprintf(
|
||||
__( 'This is your default currency. <a href="%s" target="_blank">Change in Settings</a>', 'formipay' ),
|
||||
admin_url('/admin.php?page=formipay-settings')
|
||||
);
|
||||
$cart_items['static_items']['fields']['amount_'.$currency_symbol]['required'] = true;
|
||||
$cart_items['static_items']['fields']['amount_'.$currency_symbol]['placeholder'] = __( 'Enter Price...', 'formipay' );
|
||||
}else{
|
||||
$cart_items['static_items']['fields']['amount_'.$currency_symbol]['description'] = sprintf(
|
||||
__( 'System will calculate the price in %s based on exchange rate against %s when you leave these empty.', 'formipay' ),
|
||||
$currency_symbol, $default_currency_symbol
|
||||
);
|
||||
}
|
||||
}else{
|
||||
$cart_items['static_items']['fields']['amount_'.$currency_symbol]['label'] = __( 'Item Price', 'formipay' );
|
||||
$cart_items['static_items']['fields']['amount_'.$currency_symbol]['placeholder'] = __( 'Enter Price...', 'formipay' );
|
||||
}
|
||||
}
|
||||
|
||||
$cart_items = apply_filters( 'formipay/form-settings/tab:cart/group:items', $cart_items );
|
||||
|
||||
$last_cart_items = array_key_last($cart_items);
|
||||
|
||||
@@ -15,6 +15,8 @@ class Order {
|
||||
|
||||
private $order_details;
|
||||
|
||||
private $chosen_currency;
|
||||
|
||||
/**
|
||||
* Initializes the plugin by setting filters and administration functions.
|
||||
*/
|
||||
@@ -78,7 +80,6 @@ class Order {
|
||||
wp_send_json_error([
|
||||
'message' => 'Nonce verification failed'
|
||||
]);
|
||||
// wp_send_json_error() dies internally, no need for exit
|
||||
}
|
||||
|
||||
// Sanitize and unslash inputs explicitly
|
||||
@@ -89,6 +90,7 @@ class Order {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$order_meta_data = isset($_REQUEST['meta_data']) ? wp_unslash($_REQUEST['meta_data']) : [];
|
||||
$purpose = isset($_REQUEST['purpose']) ? sanitize_text_field(wp_unslash($_REQUEST['purpose'])) : '';
|
||||
$this->currency = isset($_REQUEST['currency']) ? wp_unslash($_REQUEST['currency']) : formipay_default_currency('symbol');
|
||||
|
||||
$this->form_id = $form_id;
|
||||
|
||||
@@ -104,6 +106,7 @@ class Order {
|
||||
if ($purpose === 'calculate') {
|
||||
$order_data['total'] = $total;
|
||||
$order_data['items'] = $order_details;
|
||||
$order_data['form_data'] = formipay_get_post_meta($form_id);
|
||||
wp_send_json($order_data);
|
||||
}
|
||||
|
||||
@@ -206,64 +209,98 @@ class Order {
|
||||
|
||||
public function process_order_details() {
|
||||
|
||||
$currency_codes = [];
|
||||
$allowed_currencies = formipay_get_post_meta($this->form_id, 'allowed_currencies');
|
||||
if(!empty($allowed_currencies)){
|
||||
$parse_currencies = json_decode($allowed_currencies, true);
|
||||
foreach($parse_currencies as $currency_data){
|
||||
$parse_currency = explode(':::', $currency_data);
|
||||
$currency_codes[] = $parse_currency[0];
|
||||
}
|
||||
}
|
||||
|
||||
$details = [];
|
||||
|
||||
$product_price = floatval(formipay_get_post_meta($this->form_id, 'product_price'));
|
||||
$details[] = [
|
||||
'item' => html_entity_decode(get_the_title($this->form_id)),
|
||||
'amount' => $product_price,
|
||||
'qty' => $this->order_data['qty'],
|
||||
'subtotal' => floatval($product_price) * intval($this->order_data['qty']),
|
||||
'context' => 'main'
|
||||
];
|
||||
// $product_price = floatval(formipay_get_post_meta($this->form_id, 'product_price'));
|
||||
// $details[] = [
|
||||
// 'item' => html_entity_decode(get_the_title($this->form_id)),
|
||||
// 'amount' => $product_price,
|
||||
// 'qty' => (int) $this->order_data['qty'],
|
||||
// 'subtotal' => floatval($product_price) * intval($this->order_data['qty']),
|
||||
// 'context' => 'main'
|
||||
// ];
|
||||
|
||||
$check_fields = formipay_get_post_meta($this->form_id, 'formipay_settings');
|
||||
// $check_fields = formipay_get_post_meta($this->form_id, 'formipay_settings');
|
||||
|
||||
if(!empty($check_fields['fields'])){
|
||||
foreach($check_fields['fields'] as $field){
|
||||
// if($field['field_type'] == 'select'){
|
||||
if(in_array($field['field_type'], ['select','checkbox', 'radio'])) {
|
||||
$options = $field['field_options'];
|
||||
if(!empty($options)){
|
||||
foreach($options as $option){
|
||||
// if(!empty($check_fields['fields'])){
|
||||
// foreach($check_fields['fields'] as $field){
|
||||
// // if($field['field_type'] == 'select'){
|
||||
// if(in_array($field['field_type'], ['select','checkbox', 'radio'])) {
|
||||
// $options = $field['field_options'];
|
||||
// if(!empty($options)){
|
||||
// foreach($options as $option){
|
||||
|
||||
$option_value = ($field['show_toggle']['value'] && '' !== $option['value']) ? $option['value'] : $option['label'];
|
||||
// $option_value = ($field['show_toggle']['value'] && '' !== $option['value']) ? $option['value'] : $option['label'];
|
||||
|
||||
if(!empty($this->order_data[$field['field_id']])) {
|
||||
$field_value = $this->order_data[$field['field_id']];
|
||||
if($field['field_type'] == 'select'){
|
||||
$field_value = ($field['show_toggle']['value']) ?
|
||||
$this->order_data[$field['field_id']]['value'] :
|
||||
$this->order_data[$field['field_id']]['label'];
|
||||
}
|
||||
$field_value = explode(',', $field_value);
|
||||
// if(!empty($this->order_data[$field['field_id']])) {
|
||||
// $field_value = $this->order_data[$field['field_id']];
|
||||
// if($field['field_type'] == 'select'){
|
||||
// $field_value = ($field['show_toggle']['value']) ?
|
||||
// $this->order_data[$field['field_id']]['value'] :
|
||||
// $this->order_data[$field['field_id']]['label'];
|
||||
// }
|
||||
// $field_value = explode(',', $field_value);
|
||||
|
||||
$context = 'no-context';
|
||||
if(floatval($option['amount']) < 0){
|
||||
$context = 'sub';
|
||||
}elseif(floatval($option['amount']) > 0){
|
||||
$context = 'add';
|
||||
}
|
||||
// $context = 'no-context';
|
||||
// if(floatval($option['amount']) < 0){
|
||||
// $context = 'sub';
|
||||
// }elseif(floatval($option['amount']) > 0){
|
||||
// $context = 'add';
|
||||
// }
|
||||
|
||||
if(!empty($field_value) && $field['show_toggle']['amount'] == 'yes'){
|
||||
foreach($field_value as $f_value){
|
||||
if($option_value == $f_value){
|
||||
$qty = ($option['qty'] == 'yes') ? $this->order_data['qty'] : 1;
|
||||
$details[] = [
|
||||
'item' => $field['label'] .' - '. $option['label'],
|
||||
'amount' => floatval($option['amount']),
|
||||
'qty' => $qty,
|
||||
'subtotal' => floatval($option['amount']) * intval($qty),
|
||||
'context' => $context
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if(!empty($field_value) && $field['show_toggle']['amount'] == 'yes'){
|
||||
// foreach($field_value as $f_value){
|
||||
// if($option_value == $f_value){
|
||||
// $qty = ($option['qty'] == 'yes') ? $this->order_data['qty'] : 1;
|
||||
// $details[] = [
|
||||
// 'item' => $field['label'] .' - '. $option['label'],
|
||||
// 'amount' => floatval($option['amount']),
|
||||
// 'qty' => (int) $qty,
|
||||
// 'subtotal' => floatval($option['amount']) * intval($qty),
|
||||
// 'context' => $context
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Cart items (not implemented yet)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Attached Product
|
||||
*/
|
||||
|
||||
$products = formipay_get_post_meta($this->form_id, 'static_products');
|
||||
if(!empty($products)){
|
||||
$products = explode(',', $products);
|
||||
foreach($products as $product_id){
|
||||
$product_data = formipay_get_post_meta($product_id);
|
||||
$regular_price = formipay_get_post_meta($product_id, 'setting_product_price_regular_'.$this->currency);
|
||||
$sale_price = formipay_get_post_meta($product_id, 'setting_product_price_sale_'.$this->currency);
|
||||
$this_item = [
|
||||
'item' => html_entity_decode(get_the_title($product_id)),
|
||||
'amount' => (float) $sale_price ?: $regular_price,
|
||||
'qty' => 1,
|
||||
'subtotal' => (float) $sale_price ?: $regular_price,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ class Render {
|
||||
self::$form_ids[] = $post_id;
|
||||
}
|
||||
|
||||
$isDonation = formipay_is_donation($post_id);
|
||||
|
||||
$form_settings = get_post_meta($post_id, 'formipay_settings', true);
|
||||
$point_symbol = formipay_get_post_meta($post_id, 'multistep_point_symbol');
|
||||
$point_icons = formipay_get_post_meta($post_id, 'multistep_point_icons');
|
||||
|
||||
Reference in New Issue
Block a user