WC_Shipping_Flat_Rate::sanitize_cost
Sanitize the cost field.
Method of the class: WC_Shipping_Flat_Rate{}
No Hooks.
Returns
String.
Usage
$WC_Shipping_Flat_Rate = new WC_Shipping_Flat_Rate(); $WC_Shipping_Flat_Rate->sanitize_cost( $value );
- $value(string) (required)
- Unsanitized value.
Changelog
| Since 3.4.0 | Introduced. |
WC_Shipping_Flat_Rate::sanitize_cost() WC Shipping Flat Rate::sanitize cost code WC 10.8.1
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 );
$contains_shortcodes = false !== strpos( $value, '[' ) || false !== strpos( $value, ']' );
if ( ! $contains_shortcodes && ! $this->is_math_expression( $value ) ) {
$value = \Automattic\WooCommerce\Utilities\NumberUtil::sanitize_cost_in_current_locale( $value );
}
// Thrown an error on the front end if the evaluate_cost will fail.
$dummy_cost = $this->evaluate_cost(
$value,
array(
'cost' => 1,
'qty' => 1,
)
);
if ( false === $dummy_cost ) {
throw new Exception( WC_Eval_Math::$last_error );
}
return $value;
}