WC_Shipping_Local_Pickup::sanitize_cost()publicWC 8.3.0

Sanitize the cost field.

Method of the class: WC_Shipping_Local_Pickup{}

No Hooks.

Return

String.

Usage

$WC_Shipping_Local_Pickup = new WC_Shipping_Local_Pickup();
$WC_Shipping_Local_Pickup->sanitize_cost( $value );
$value(string) (required)
Unsanitized value.

Changelog

Since 8.3.0 Introduced.

WC_Shipping_Local_Pickup::sanitize_cost() code WC 9.3.3

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

	$test_value = str_replace( wc_get_price_decimal_separator(), '.', $value );
	$test_value = str_replace( array( get_woocommerce_currency_symbol(), html_entity_decode( get_woocommerce_currency_symbol() ), wc_get_price_thousand_separator() ), '', $test_value );

	if ( $test_value && ! is_numeric( $test_value ) ) {
		throw new Exception( __( 'Please enter a valid number', 'woocommerce' ) );
	}

	return $value;
}