Merged in feature/117-dev-dev01 (pull request #8)
auto-patch 117-dev-dev01-2023-12-15T16_09_06 * auto-patch 117-dev-dev01-2023-12-15T16_09_06
This commit is contained in:
@@ -281,7 +281,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
|
||||
public function sanitize_cost( $value ) {
|
||||
$value = is_null( $value ) ? '' : $value;
|
||||
$value = wp_kses_post( trim( wp_unslash( $value ) ) );
|
||||
$value = str_replace( array( get_woocommerce_currency_symbol(), html_entity_decode( get_woocommerce_currency_symbol() ) ), '', $value );
|
||||
$value = str_replace( array( get_woocommerce_currency_symbol(), html_entity_decode( get_woocommerce_currency_symbol() ), wc_get_price_thousand_separator() ), '', $value );
|
||||
// Thrown an error on the front end if the evaluate_cost will fail.
|
||||
$dummy_cost = $this->evaluate_cost(
|
||||
$value,
|
||||
|
||||
@@ -8,13 +8,15 @@
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$cost_desc = __( 'Enter a cost (excl. tax) or sum, e.g. <code>10.00 * [qty]</code>.', 'woocommerce' ) . '<br/><br/>' . __( 'Use <code>[qty]</code> for the number of items, <br/><code>[cost]</code> for the total cost of items, and <code>[fee percent="10" min_fee="20" max_fee=""]</code> for percentage based fees.', 'woocommerce' );
|
||||
$cost_link = sprintf( '<span id="wc-shipping-advanced-costs-help-text">%s <a target="_blank" href="https://woo.com/document/flat-rate-shipping/#advanced-costs">%s</a>.</span>', __( 'Charge a flat rate per item, or enter a cost formula to charge a percentage based cost or a minimum fee. Learn more about', 'woocommerce' ), __( 'advanced costs', 'woocommerce' ) );
|
||||
|
||||
$settings = array(
|
||||
'title' => array(
|
||||
'title' => __( 'Method title', 'woocommerce' ),
|
||||
'title' => __( 'Name', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
|
||||
'description' => __( 'Your customers will see the name of this shipping method during checkout.', 'woocommerce' ),
|
||||
'default' => __( 'Flat rate', 'woocommerce' ),
|
||||
'placeholder' => __( 'e.g. Standard national', 'woocommerce' ),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
'tax_status' => array(
|
||||
@@ -30,6 +32,7 @@ $settings = array(
|
||||
'cost' => array(
|
||||
'title' => __( 'Cost', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'class' => 'wc-shipping-modal-price',
|
||||
'placeholder' => '',
|
||||
'description' => $cost_desc,
|
||||
'default' => '0',
|
||||
@@ -45,8 +48,8 @@ if ( ! empty( $shipping_classes ) ) {
|
||||
'title' => __( 'Shipping class costs', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'default' => '',
|
||||
/* translators: %s: URL for link. */
|
||||
'description' => sprintf( __( 'These costs can optionally be added based on the <a href="%s">product shipping class</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=classes' ) ),
|
||||
/* translators: %s: URL for link */
|
||||
'description' => sprintf( __( 'These costs can optionally be added based on the <a target="_blank" href="%s">product shipping class</a>. Learn more about <a target="_blank" href="https://woo.com/document/flat-rate-shipping/#shipping-classes">setting shipping class costs</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=classes' ) ),
|
||||
);
|
||||
foreach ( $shipping_classes as $shipping_class ) {
|
||||
if ( ! isset( $shipping_class->term_id ) ) {
|
||||
@@ -56,6 +59,7 @@ if ( ! empty( $shipping_classes ) ) {
|
||||
/* translators: %s: shipping class name */
|
||||
'title' => sprintf( __( '"%s" shipping class cost', 'woocommerce' ), esc_html( $shipping_class->name ) ),
|
||||
'type' => 'text',
|
||||
'class' => 'wc-shipping-modal-price',
|
||||
'placeholder' => __( 'N/A', 'woocommerce' ),
|
||||
'description' => $cost_desc,
|
||||
'default' => $this->get_option( 'class_cost_' . $shipping_class->slug ), // Before 2.5.0, we used slug here which caused issues with long setting names.
|
||||
@@ -67,6 +71,7 @@ if ( ! empty( $shipping_classes ) ) {
|
||||
$settings['no_class_cost'] = array(
|
||||
'title' => __( 'No shipping class cost', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'class' => 'wc-shipping-modal-price',
|
||||
'placeholder' => __( 'N/A', 'woocommerce' ),
|
||||
'description' => $cost_desc,
|
||||
'default' => '',
|
||||
@@ -75,14 +80,15 @@ if ( ! empty( $shipping_classes ) ) {
|
||||
);
|
||||
|
||||
$settings['type'] = array(
|
||||
'title' => __( 'Calculation type', 'woocommerce' ),
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'default' => 'class',
|
||||
'options' => array(
|
||||
'title' => __( 'Calculation type', 'woocommerce' ),
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'default' => 'class',
|
||||
'options' => array(
|
||||
'class' => __( 'Per class: Charge shipping for each shipping class individually', 'woocommerce' ),
|
||||
'order' => __( 'Per order: Charge shipping for the most expensive shipping class', 'woocommerce' ),
|
||||
),
|
||||
'description' => $cost_link,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,38 +83,61 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
|
||||
add_action( 'admin_footer', array( 'WC_Shipping_Free_Shipping', 'enqueue_admin_js' ), 10 ); // Priority needs to be higher than wc_print_js (25).
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the cost field.
|
||||
*
|
||||
* @since 8.3.0
|
||||
* @param string $value Unsanitized value.
|
||||
* @throws Exception Last error triggered.
|
||||
* @return string
|
||||
*/
|
||||
public function sanitize_cost( $value ) {
|
||||
$value = is_null( $value ) ? '' : $value;
|
||||
$value = wp_kses_post( trim( wp_unslash( $value ) ) );
|
||||
$value = str_replace( array( get_woocommerce_currency_symbol(), html_entity_decode( get_woocommerce_currency_symbol() ), wc_get_price_thousand_separator() ), '', $value );
|
||||
|
||||
if ( ! is_numeric( $value ) ) {
|
||||
throw new Exception( __( 'Please enter a valid number', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init form fields.
|
||||
*/
|
||||
public function init_form_fields() {
|
||||
$this->instance_form_fields = array(
|
||||
'title' => array(
|
||||
'title' => __( 'Title', 'woocommerce' ),
|
||||
'title' => __( 'Name', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
|
||||
'description' => __( 'Your customers will see the name of this shipping method during checkout.', 'woocommerce' ),
|
||||
'default' => $this->method_title,
|
||||
'placeholder' => __( 'e.g. Free shipping', 'woocommerce' ),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
'requires' => array(
|
||||
'title' => __( 'Free shipping requires...', 'woocommerce' ),
|
||||
'title' => __( 'Free shipping requires', 'woocommerce' ),
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'default' => '',
|
||||
'options' => array(
|
||||
'' => __( 'N/A', 'woocommerce' ),
|
||||
'' => __( 'No requirement', 'woocommerce' ),
|
||||
'coupon' => __( 'A valid free shipping coupon', 'woocommerce' ),
|
||||
'min_amount' => __( 'A minimum order amount', 'woocommerce' ),
|
||||
'either' => __( 'A minimum order amount OR a coupon', 'woocommerce' ),
|
||||
'both' => __( 'A minimum order amount AND a coupon', 'woocommerce' ),
|
||||
'either' => __( 'A minimum order amount OR coupon', 'woocommerce' ),
|
||||
'both' => __( 'A minimum order amount AND coupon', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
'min_amount' => array(
|
||||
'title' => __( 'Minimum order amount', 'woocommerce' ),
|
||||
'type' => 'price',
|
||||
'placeholder' => wc_format_localized_price( 0 ),
|
||||
'description' => __( 'Users will need to spend this amount to get free shipping (if enabled above).', 'woocommerce' ),
|
||||
'default' => '0',
|
||||
'desc_tip' => true,
|
||||
'title' => __( 'Minimum order amount', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'class' => 'wc-shipping-modal-price',
|
||||
'placeholder' => wc_format_localized_price( 0 ),
|
||||
'description' => __( 'Customers will need to spend this amount to get free shipping.', 'woocommerce' ),
|
||||
'default' => '0',
|
||||
'desc_tip' => true,
|
||||
'sanitize_callback' => array( $this, 'sanitize_cost' ),
|
||||
),
|
||||
'ignore_discounts' => array(
|
||||
'title' => __( 'Coupons discounts', 'woocommerce' ),
|
||||
|
||||
@@ -79,16 +79,37 @@ class WC_Shipping_Local_Pickup extends WC_Shipping_Method {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the cost field.
|
||||
*
|
||||
* @since 8.3.0
|
||||
* @param string $value Unsanitized value.
|
||||
* @throws Exception Last error triggered.
|
||||
* @return string
|
||||
*/
|
||||
public function sanitize_cost( $value ) {
|
||||
$value = is_null( $value ) ? '' : $value;
|
||||
$value = wp_kses_post( trim( wp_unslash( $value ) ) );
|
||||
$value = str_replace( array( get_woocommerce_currency_symbol(), html_entity_decode( get_woocommerce_currency_symbol() ), wc_get_price_thousand_separator() ), '', $value );
|
||||
|
||||
if ( $value && ! is_numeric( $value ) ) {
|
||||
throw new Exception( __( 'Please enter a valid number', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init form fields.
|
||||
*/
|
||||
public function init_form_fields() {
|
||||
$this->instance_form_fields = array(
|
||||
'title' => array(
|
||||
'title' => __( 'Title', 'woocommerce' ),
|
||||
'title' => __( 'Name', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
|
||||
'description' => __( 'Your customers will see the name of this shipping method during checkout.', 'woocommerce' ),
|
||||
'default' => __( 'Local pickup', 'woocommerce' ),
|
||||
'placeholder' => __( 'e.g. Local pickup', 'woocommerce' ),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
'tax_status' => array(
|
||||
@@ -102,12 +123,14 @@ class WC_Shipping_Local_Pickup extends WC_Shipping_Method {
|
||||
),
|
||||
),
|
||||
'cost' => array(
|
||||
'title' => __( 'Cost', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'placeholder' => '0',
|
||||
'description' => __( 'Optional cost for local pickup.', 'woocommerce' ),
|
||||
'default' => '',
|
||||
'desc_tip' => true,
|
||||
'title' => __( 'Cost', 'woocommerce' ),
|
||||
'type' => 'text',
|
||||
'class' => 'wc-shipping-modal-price',
|
||||
'placeholder' => wc_format_localized_price( 0 ),
|
||||
'description' => __( 'Optional cost for local pickup.', 'woocommerce' ),
|
||||
'default' => '',
|
||||
'desc_tip' => true,
|
||||
'sanitize_callback' => array( $this, 'sanitize_cost' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user