Merge pull request #13296 from woocommerce/coupons-format-code

Replace woocommerce_coupon_code filter by wc_format_coupon_code()
This commit is contained in:
Mike Jolley 2017-02-22 17:44:41 +00:00 committed by GitHub
commit 868f685818
7 changed files with 11 additions and 11 deletions

View File

@ -260,7 +260,7 @@ class WC_Meta_Box_Coupon_Data {
global $wpdb;
// Check for dupe coupons
$coupon_code = apply_filters( 'woocommerce_coupon_code', $post->post_title );
$coupon_code = wc_format_coupon_code( $post->post_title );
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $post_id );
if ( $id_from_code ) {

View File

@ -232,7 +232,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
if ( ! is_null( $value ) ) {
switch ( $key ) {
case 'code' :
$coupon_code = apply_filters( 'woocommerce_coupon_code', $value );
$coupon_code = wc_format_coupon_code( $value );
$id = $coupon->get_id() ? $coupon->get_id() : 0;
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );

View File

@ -121,7 +121,7 @@ class WC_REST_Legacy_Coupons_Controller extends WC_REST_CRUD_Controller {
if ( ! is_null( $value ) ) {
switch ( $key ) {
case 'code' :
$coupon_code = apply_filters( 'woocommerce_coupon_code', $value );
$coupon_code = wc_format_coupon_code( $value );
$id = $coupon->get_id() ? $coupon->get_id() : 0;
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );

View File

@ -222,7 +222,7 @@ class WC_API_Coupons extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_missing_coupon_code', sprintf( __( 'Missing parameter %s', 'woocommerce' ), 'code' ), 400 );
}
$coupon_code = apply_filters( 'woocommerce_coupon_code', $data['code'] );
$coupon_code = wc_format_coupon_code( $data['code'] );
$id_from_code = wc_get_coupon_id_by_code( $coupon_code );
if ( $id_from_code ) {
@ -329,7 +329,7 @@ class WC_API_Coupons extends WC_API_Resource {
if ( isset( $data['code'] ) ) {
global $wpdb;
$coupon_code = apply_filters( 'woocommerce_coupon_code', $data['code'] );
$coupon_code = wc_format_coupon_code( $data['code'] );
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );
if ( $id_from_code ) {

View File

@ -222,7 +222,7 @@ class WC_API_Coupons extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_missing_coupon_code', sprintf( __( 'Missing parameter %s', 'woocommerce' ), 'code' ), 400 );
}
$coupon_code = apply_filters( 'woocommerce_coupon_code', $data['code'] );
$coupon_code = wc_format_coupon_code( $data['code'] );
$id_from_code = wc_get_coupon_id_by_code( $coupon_code );
if ( $id_from_code ) {
@ -329,7 +329,7 @@ class WC_API_Coupons extends WC_API_Resource {
if ( isset( $data['code'] ) ) {
global $wpdb;
$coupon_code = apply_filters( 'woocommerce_coupon_code', $data['code'] );
$coupon_code = wc_format_coupon_code( $data['code'] );
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );
if ( $id_from_code ) {

View File

@ -257,7 +257,7 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_Controller {
if ( ! is_null( $value ) ) {
switch ( $key ) {
case 'code' :
$coupon_code = apply_filters( 'woocommerce_coupon_code', $value );
$coupon_code = wc_format_coupon_code( $value );
$id = $coupon->get_id() ? $coupon->get_id() : 0;
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );

View File

@ -1703,7 +1703,7 @@ class WC_Cart {
* @return bool
*/
public function has_discount( $coupon_code = '' ) {
return $coupon_code ? in_array( apply_filters( 'woocommerce_coupon_code', $coupon_code ), $this->applied_coupons ) : sizeof( $this->applied_coupons ) > 0;
return $coupon_code ? in_array( wc_format_coupon_code( $coupon_code ), $this->applied_coupons ) : sizeof( $this->applied_coupons ) > 0;
}
/**
@ -1719,7 +1719,7 @@ class WC_Cart {
}
// Sanitize coupon code
$coupon_code = apply_filters( 'woocommerce_coupon_code', $coupon_code );
$coupon_code = wc_format_coupon_code( $coupon_code );
// Get the coupon
$the_coupon = new WC_Coupon( $coupon_code );
@ -1852,7 +1852,7 @@ class WC_Cart {
}
// Get the coupon
$coupon_code = apply_filters( 'woocommerce_coupon_code', $coupon_code );
$coupon_code = wc_format_coupon_code( $coupon_code );
$position = array_search( $coupon_code, $this->applied_coupons );
if ( false !== $position ) {