WC_Shipping_Flat_Rate::sanitize_cost()publicWC 3.4.0

Sanitize the cost field.

Method of the class: WC_Shipping_Flat_Rate{}

No Hooks.

Return

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() code WC 8.7.0

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 );
	// 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;
}