WordPress at Your Fingertips
function is not described

WC_Shipping_Flat_Rate::sanitize_cost() public WC 3.4.0

Sanitize the cost field.

{} It's a 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.

Code of WC_Shipping_Flat_Rate::sanitize_cost() WC 5.9.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;
}