golden hour
/home/godaofbq/hyperbaric-revolution.com/wp-content/plugins/discountify/core/admin/settings
⬆️ Go Up
Upload
File/Folder
Size
Actions
.htaccess
237 B
Del
OK
form.php
1.26 KB
Del
OK
settings-fields.php
9.28 KB
Del
OK
settings.php
4.19 KB
Del
OK
tab-content
-
Del
OK
table.php
7.68 KB
Del
OK
Edit: settings.php
<?php namespace Discountify\Core\Admin\Settings; use Discountify\Utils\Singleton; /** * Class Menu */ class Settings{ use Singleton; /** * Initialize * * @return void */ public function init() { $callback = array('save_settings','get_discount_rule'); if ( ! empty( $callback ) ) { foreach ( $callback as $key => $value ) { add_action( 'wp_ajax_' . $value, [$this, $value] ); add_action( 'wp_ajax_nopriv_' . $value, [$this, $value] ); } } } public function rules_init() { add_action( 'init', [$this, 'save_discount_rules' ] ); } /** * Save settings */ public function save_settings() { \Discountify\Utils\Helper::instance()->verify_nonce('discountify_nonce', sanitize_key($_POST['discountify_nonce']) ); $post_data = !empty( $_POST['params'] ) ? map_deep( $_POST['params'], 'sanitize_text_field' ) : array(); $params = !empty($post_data) ? $post_data : []; $message = ''; if (!empty($params['discountify_settings']) && $params['discountify_settings'] == 'discountify_settings' ) { $settings_key = \Discountify\Utils\Helper::get_settings_key(); foreach ($settings_key as $key => $value) { if ( $key == 'cart_total' || $key == 'shipping_cart' ){ $totals = array(); foreach ( $params['multi_discounts['.$key.''] as $index => $item) { if (!empty($item['total']) && !empty($item['discount']) ) { $totals[] = array( 'total'=> $item['total'] , 'discount' => $item['discount']) ; } } $settings_key[''.$key.''] = $totals; }else{ $settings_key[$key] = !empty( $params[$key] ) ? $params[$key] : ""; } } update_option( 'discountify_settings' , $settings_key ); $message = esc_html__('Settings Save Successfully','discountify'); } wp_send_json_success( array( 'message' => $message) ); wp_die(); } /** * Save discount rules */ public function save_discount_rules() { if ( empty( $_POST ) || empty( $_POST['save_discount'] ) ) { return; } \Discountify\Utils\Helper::instance()->verify_nonce('save_discount_rules', sanitize_key($_POST['save_discount_rules']) ); $fields = [ 'enable_rules' , 'enable_user_discount' ]; foreach ($fields as $field) { if ( empty( $_POST[$field] ) ) { $_POST[$field] = 'no'; } } $this->insert_rules( $_POST ); esc_html__('Rules Added Successfully','discountify'); } /** * insert rules */ public function insert_rules( $params ) { $discount_name = !empty( $params['discount_name'] ) ? $params['discount_name'] : esc_html__('Discount','discountify'); $ID = !empty( $params['ID'] ) ? $params['ID'] : ''; if ( $ID == "" ) { $id = wp_insert_post(array( 'post_title'=> $discount_name , 'post_type'=>'discountify_rules', 'post_content'=>'', 'post_status' => 'publish' )); }else{ $post_update = array( 'ID' => $ID, 'post_title' => $discount_name ); wp_update_post( $post_update ); $id = $ID; } if (!empty( $id ) ) { foreach ($params as $key => $value) { $meta_key = $key; if ( 'multi_discounts' == $key ) { $meta_key = 'multi_discounts'; $repeat_items = $params[$key][$params['rules_type']]; foreach ($repeat_items as $index => &$item) { if (empty($item['min'])) { unset($repeat_items[$index]); } } $value = $repeat_items; } else { $meta_key = $key; } update_post_meta( $id, $meta_key, $value ); } } } public function format_item($value) { foreach ($value as $index => &$item) { if (empty($item['min'])) { unset($value[$index]); } } return $value; } /** * Get discount rule */ public function get_discount_rule() { \Discountify\Utils\Helper::instance()->verify_nonce('discountify_nonce', sanitize_key($_POST['discountify_nonce']) ); $id = !empty( $_POST['id'] ) ? absint( $_POST['id'] ) : ''; if (!empty( $id ) ) { $rule = \Discountify\Utils\Helper::get_single_rule($id); wp_send_json_success( array( 'data' => $rule )); }else{ wp_send_json_error( array( 'message' => esc_html__('ID Missing','discountify'), )); } wp_die(); } }
Save