Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@@ -9,7 +9,7 @@
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Discount_Code;
use WP_Ultimo\Models\Discount_Code;
/**
* Returns a discount code object searching by the code.
@@ -22,8 +22,7 @@ use \WP_Ultimo\Models\Discount_Code;
function wu_get_discount_code_by_code($coupon_code) {
return \WP_Ultimo\Models\Discount_Code::get_by('code', $coupon_code);
} // end wu_get_discount_code_by_code;
}
/**
* Gets a discount code based on the ID.
*
@@ -35,8 +34,7 @@ function wu_get_discount_code_by_code($coupon_code) {
function wu_get_discount_code($discount_code_id) {
return \WP_Ultimo\Models\Discount_Code::get_by_id($discount_code_id);
} // end wu_get_discount_code;
}
/**
* Queries discount codes.
@@ -49,8 +47,7 @@ function wu_get_discount_code($discount_code_id) {
function wu_get_discount_codes($query = array()) {
return \WP_Ultimo\Models\Discount_Code::query($query);
} // end wu_get_discount_codes;
}
/**
* Calculates the discounted price after running it through the discount code.
*
@@ -65,24 +62,17 @@ function wu_get_discount_codes($query = array()) {
function wu_get_discounted_price($base_price, $amount, $type, $format = true) {
if ($type === 'percentage') {
$discounted_price = $base_price - ($base_price * ($amount / 100));
} elseif ($type === 'absolute') {
$discounted_price = $base_price - $amount;
}
} // end if;
if (!$format) {
if ( ! $format) {
return $discounted_price;
} // end if;
}
return number_format((float) $discounted_price, 2);
} // end wu_get_discounted_price;
}
/**
* Creates a new discount code.
*
@@ -95,24 +85,26 @@ function wu_get_discounted_price($base_price, $amount, $type, $format = true) {
*/
function wu_create_discount_code($discount_code_data) {
$discount_code_data = wp_parse_args($discount_code_data, array(
'max_uses' => true,
'name' => false,
'code' => false,
'value' => false,
'setup_fee_value' => false,
'start_date' => false,
'active' => true,
'expiration_date' => false,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'skip_validation' => false,
));
$discount_code_data = wp_parse_args(
$discount_code_data,
array(
'max_uses' => true,
'name' => false,
'code' => false,
'value' => false,
'setup_fee_value' => false,
'start_date' => false,
'active' => true,
'expiration_date' => false,
'date_created' => wu_get_current_time('mysql', true),
'date_modified' => wu_get_current_time('mysql', true),
'skip_validation' => false,
)
);
$discount_code = new Discount_Code($discount_code_data);
$saved = $discount_code->save();
return is_wp_error($saved) ? $saved : $discount_code;
} // end wu_create_discount_code;
}