commit
3c482f2fe0
|
@ -588,7 +588,8 @@ class WC_Form_Handler {
|
|||
|
||||
foreach ( $item->get_meta_data() as $meta ) {
|
||||
if ( taxonomy_is_product_attribute( $meta->key ) ) {
|
||||
$variations[ $meta->key ] = $meta->value;
|
||||
$term = get_term_by( 'slug', $meta->value, $meta->key );
|
||||
$variations[ $meta->key ] = $term ? $term->name : $meta->value;
|
||||
} elseif ( meta_is_product_attribute( $meta->key, $meta->value, $product_id ) ) {
|
||||
$variations[ $meta->key ] = $meta->value;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,33 @@ class WC_Geolocation {
|
|||
return $new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if is a valid IP address.
|
||||
*
|
||||
* @since 3.0.6
|
||||
* @param string $ip_address IP address.
|
||||
* @return string|bool The valid IP address, otherwise false.
|
||||
*/
|
||||
private function is_ip_address( $ip_address ) {
|
||||
// WP 4.7+ only.
|
||||
if ( function_exists( 'rest_is_ip_address' ) ) {
|
||||
return rest_is_ip_address( $ip_address );
|
||||
}
|
||||
|
||||
// Support for WordPress 4.4 to 4.6.
|
||||
if ( ! class_exists( 'Requests_IPv6', false ) ) {
|
||||
include_once( dirname( __FILE__ ) . '/vendor/class-requests-ipv6.php' );
|
||||
}
|
||||
|
||||
$ipv4_pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/';
|
||||
|
||||
if ( ! preg_match( $ipv4_pattern, $ip ) && ! Requests_IPv6::check_ipv6( $ip ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user IP Address.
|
||||
* @return string
|
||||
|
@ -76,7 +103,7 @@ class WC_Geolocation {
|
|||
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
|
||||
// Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
|
||||
// Make sure we always only send through the first IP in the list which should always be the client IP.
|
||||
return trim( current( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) );
|
||||
return (string) self::is_ip_address( trim( current( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) );
|
||||
} elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
@ -90,8 +117,12 @@ class WC_Geolocation {
|
|||
* @return string
|
||||
*/
|
||||
public static function get_external_ip_address() {
|
||||
$transient_name = 'external_ip_address_' . self::get_ip_address();
|
||||
$external_ip_address = get_transient( $transient_name );
|
||||
$external_ip_address = '0.0.0.0';
|
||||
|
||||
if ( '' !== self::get_ip_address() ) {
|
||||
$transient_name = 'external_ip_address_' . self::get_ip_address();
|
||||
$external_ip_address = get_transient( $transient_name );
|
||||
}
|
||||
|
||||
if ( false === $external_ip_address ) {
|
||||
$external_ip_address = '0.0.0.0';
|
||||
|
|
|
@ -65,6 +65,7 @@ class WC_Validation {
|
|||
$valid = (bool) preg_match( '/^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$/', $postcode );
|
||||
break;
|
||||
case 'ES' :
|
||||
case 'FR' :
|
||||
$valid = (bool) preg_match( '/^([0-9]{5})$/i', $postcode );
|
||||
break;
|
||||
case 'GB' :
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses
|
||||
*
|
||||
* @package Requests
|
||||
* @subpackage Utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses
|
||||
*
|
||||
* This was originally based on the PEAR class of the same name, but has been
|
||||
* entirely rewritten.
|
||||
*
|
||||
* @package Requests
|
||||
* @subpackage Utilities
|
||||
*/
|
||||
class Requests_IPv6 {
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and expands the '::' to
|
||||
* the required number of zero pieces.
|
||||
*
|
||||
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
||||
* ::1 -> 0:0:0:0:0:0:0:1
|
||||
*
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The uncompressed IPv6 address
|
||||
*/
|
||||
public static function uncompress( $ip ) {
|
||||
if ( substr_count( $ip, '::' ) !== 1 ) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
list($ip1, $ip2) = explode( '::', $ip );
|
||||
$c1 = ( '' == $ip1 ) ? -1 : substr_count( $ip1, ':' );
|
||||
$c2 = ( '' == $ip2 ) ? -1 : substr_count( $ip2, ':' );
|
||||
|
||||
if ( strpos( $ip2, '.' ) !== false ) {
|
||||
$c2++;
|
||||
}
|
||||
// ::
|
||||
if ( -1 === $c1 && -1 === $c2 ) {
|
||||
$ip = '0:0:0:0:0:0:0:0';
|
||||
} // ::xxx
|
||||
elseif ( -1 === $c1 ) {
|
||||
$fill = str_repeat( '0:', 7 - $c2 );
|
||||
$ip = str_replace( '::', $fill, $ip );
|
||||
} // xxx::
|
||||
elseif ( -1 === $c2 ) {
|
||||
$fill = str_repeat( ':0', 7 - $c1 );
|
||||
$ip = str_replace( '::', $fill, $ip );
|
||||
} // xxx::xxx
|
||||
else {
|
||||
$fill = ':' . str_repeat( '0:', 6 - $c2 - $c1 );
|
||||
$ip = str_replace( '::', $fill, $ip );
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and compresses consecutive
|
||||
* zero pieces to '::'.
|
||||
*
|
||||
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
|
||||
* 0:0:0:0:0:0:0:1 -> ::1
|
||||
*
|
||||
* @see uncompress()
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The compressed IPv6 address
|
||||
*/
|
||||
public static function compress( $ip ) {
|
||||
// Prepare the IP to be compressed
|
||||
$ip = self::uncompress( $ip );
|
||||
$ip_parts = self::split_v6_v4( $ip );
|
||||
|
||||
// Replace all leading zeros
|
||||
$ip_parts[0] = preg_replace( '/(^|:)0+([0-9])/', '\1\2', $ip_parts[0] );
|
||||
|
||||
// Find bunches of zeros
|
||||
if ( preg_match_all( '/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE ) ) {
|
||||
$max = 0;
|
||||
$pos = null;
|
||||
foreach ( $matches[0] as $match ) {
|
||||
if ( strlen( $match[0] ) > $max ) {
|
||||
$max = strlen( $match[0] );
|
||||
$pos = $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
$ip_parts[0] = substr_replace( $ip_parts[0], '::', $pos, $max );
|
||||
}
|
||||
|
||||
if ( '' !== $ip_parts[1] ) {
|
||||
return implode( ':', $ip_parts );
|
||||
} else {
|
||||
return $ip_parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits an IPv6 address into the IPv6 and IPv4 representation parts
|
||||
*
|
||||
* RFC 4291 allows you to represent the last two parts of an IPv6 address
|
||||
* using the standard IPv4 representation
|
||||
*
|
||||
* Example: 0:0:0:0:0:0:13.1.68.3
|
||||
* 0:0:0:0:0:FFFF:129.144.52.38
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part
|
||||
*/
|
||||
protected static function split_v6_v4( $ip ) {
|
||||
if ( strpos( $ip, '.' ) !== false ) {
|
||||
$pos = strrpos( $ip, ':' );
|
||||
$ipv6_part = substr( $ip, 0, $pos );
|
||||
$ipv4_part = substr( $ip, $pos + 1 );
|
||||
return array( $ipv6_part, $ipv4_part );
|
||||
} else {
|
||||
return array( $ip, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks an IPv6 address
|
||||
*
|
||||
* Checks if the given IP is a valid IPv6 address
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return bool true if $ip is a valid IPv6 address
|
||||
*/
|
||||
public static function check_ipv6( $ip ) {
|
||||
$ip = self::uncompress( $ip );
|
||||
list($ipv6, $ipv4) = self::split_v6_v4( $ip );
|
||||
$ipv6 = explode( ':', $ipv6 );
|
||||
$ipv4 = explode( '.', $ipv4 );
|
||||
if ( count( $ipv6 ) === 8 && count( $ipv4 ) === 1 || count( $ipv6 ) === 6 && count( $ipv4 ) === 4 ) {
|
||||
foreach ( $ipv6 as $ipv6_part ) {
|
||||
// The section can't be empty
|
||||
if ( '' === $ipv6_part ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Nor can it be over four characters
|
||||
if ( strlen( $ipv6_part ) > 4 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove leading zeros (this is safe because of the above)
|
||||
$ipv6_part = ltrim( $ipv6_part, '0' );
|
||||
if ( '' === $ipv6_part ) {
|
||||
$ipv6_part = '0';
|
||||
}
|
||||
|
||||
// Check the value is valid
|
||||
$value = hexdec( $ipv6_part );
|
||||
if ( dechex( $value ) !== strtolower( $ipv6_part ) || $value < 0 || $value > 0xFFFF ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( count( $ipv4 ) === 4 ) {
|
||||
foreach ( $ipv4 as $ipv4_part ) {
|
||||
$value = (int) $ipv4_part;
|
||||
if ( (string) $value !== $ipv4_part || $value < 0 || $value > 0xFF ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1981,7 +1981,7 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) {
|
|||
|
||||
$field .= '<input type="hidden" class="hidden" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" value="" ' . implode( ' ', $custom_attributes ) . ' placeholder="' . esc_attr( $args['placeholder'] ) . '" />';
|
||||
|
||||
} elseif ( is_array( $states ) ) {
|
||||
} elseif ( ! is_null( $current_cc ) && is_array( $states ) ) {
|
||||
|
||||
$field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="state_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ) . '">
|
||||
<option value="">' . esc_html__( 'Select a state…', 'woocommerce' ) . '</option>';
|
||||
|
@ -2419,7 +2419,7 @@ if ( ! function_exists( 'wc_display_item_meta' ) ) {
|
|||
) );
|
||||
|
||||
foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) {
|
||||
$value = $args['autop'] ? wp_kses_post( wpautop( make_clickable( $meta->display_value ) ) ) : wp_kses_post( make_clickable( $meta->display_value ) );
|
||||
$value = $args['autop'] ? wp_kses_post( $meta->display_value ) : wp_kses_post( make_clickable( trim( strip_tags( $meta->display_value ) ) ) );
|
||||
$strings[] = '<strong class="wc-item-meta-label">' . wp_kses_post( $meta->display_key ) . ':</strong> ' . $value;
|
||||
}
|
||||
|
||||
|
@ -2546,17 +2546,43 @@ function wc_get_stock_html( $product ) {
|
|||
*
|
||||
* @since 3.0.0
|
||||
* @param float $rating Rating being shown.
|
||||
* @param int $count Total number of ratings.
|
||||
* @return string
|
||||
*/
|
||||
function wc_get_rating_html( $rating ) {
|
||||
if ( $rating > 0 ) {
|
||||
$rating_html = '<div class="star-rating" title="' . sprintf( esc_attr__( 'Rated %s out of 5', 'woocommerce' ), $rating ) . '">';
|
||||
$rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . esc_html__( 'out of 5', 'woocommerce' ) . '</span>';
|
||||
$rating_html .= '</div>';
|
||||
function wc_get_rating_html( $rating, $count = 0 ) {
|
||||
if ( 0 < $rating ) {
|
||||
$html = '<div class="star-rating">';
|
||||
$html .= wc_get_star_rating_html( $rating, $count );
|
||||
$html .= '</div>';
|
||||
} else {
|
||||
$rating_html = '';
|
||||
$html = '';
|
||||
}
|
||||
return apply_filters( 'woocommerce_product_get_rating_html', $rating_html, $rating );
|
||||
|
||||
return apply_filters( 'woocommerce_product_get_rating_html', $html, $rating, $count );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML for star rating.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @param float $rating Rating being shown.
|
||||
* @param int $count Total number of ratings.
|
||||
* @return string
|
||||
*/
|
||||
function wc_get_star_rating_html( $rating, $count = 0 ) {
|
||||
$html = '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%">';
|
||||
|
||||
if ( 0 < $count ) {
|
||||
/* translators: 1: rating 2: rating count */
|
||||
$html .= sprintf( _n( 'Rated %1$s out of 5 based on %2$s customer rating', 'Rated %1$s out of 5 based on %2$s customer ratings', $count, 'woocommerce' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>', '<span class="rating">' . esc_html( $count ) . '</span>' );
|
||||
} else {
|
||||
/* translators: %s: rating */
|
||||
$html .= sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>' );
|
||||
}
|
||||
|
||||
$html .= '</span>';
|
||||
|
||||
return apply_filters( 'woocommerce_get_star_rating_html', $html, $rating, $count );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -184,9 +184,9 @@ class WC_Widget_Rating_Filter extends WC_Widget {
|
|||
|
||||
echo '<a href="' . esc_url( apply_filters( 'woocommerce_rating_filter_link', $link ) ) . '">';
|
||||
|
||||
echo '<span class="star-rating">
|
||||
<span style="width:' . esc_attr( ( $rating / 5 ) * 100 ) . '%">' . sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), $rating ) . '</span>
|
||||
</span> (' . esc_html( $count ) . ')';
|
||||
echo '<span class="star-rating">';
|
||||
echo wc_get_star_rating_html( $rating );
|
||||
echo '</span> (' . esc_html( $count ) . ')';
|
||||
|
||||
echo '</a>';
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
* happen. When this occurs the version of the template file will be bumped and
|
||||
* the readme will list any important changes.
|
||||
*
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 2.3.2
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
global $product;
|
||||
|
||||
if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
|
||||
if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -33,25 +33,7 @@ $average = $product->get_average_rating();
|
|||
if ( $rating_count > 0 ) : ?>
|
||||
|
||||
<div class="woocommerce-product-rating">
|
||||
<div class="star-rating">
|
||||
<span style="width:<?php echo ( ( $average / 5 ) * 100 ); ?>%">
|
||||
<?php
|
||||
/* translators: 1: average rating 2: max rating (i.e. 5) */
|
||||
printf(
|
||||
__( '%1$s out of %2$s', 'woocommerce' ),
|
||||
'<strong class="rating">' . esc_html( $average ) . '</strong>',
|
||||
'<span>5</span>'
|
||||
);
|
||||
?>
|
||||
<?php
|
||||
/* translators: %s: rating count */
|
||||
printf(
|
||||
_n( 'based on %s customer rating', 'based on %s customer ratings', $rating_count, 'woocommerce' ),
|
||||
'<span class="rating">' . esc_html( $rating_count ) . '</span>'
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
</div>
|
||||
<?php echo wc_get_rating_html( $average, $rating_count ); ?>
|
||||
<?php if ( comments_open() ) : ?><a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s customer review', '%s customer reviews', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.0.0
|
||||
* @version 3.1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -23,13 +23,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
global $comment;
|
||||
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
|
||||
|
||||
if ( $rating && get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) { ?>
|
||||
|
||||
<div class="star-rating">
|
||||
<span style="width:<?php echo ( esc_attr( $rating ) / 5 ) * 100; ?>%"><?php
|
||||
/* translators: %s: rating */
|
||||
printf( esc_html__( '%s out of 5', 'woocommerce' ), '<strong>' . $rating . '</strong>' );
|
||||
?></span>
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
if ( $rating && 'yes' === get_option( 'woocommerce_enable_review_rating' ) ) {
|
||||
echo wc_get_rating_html( $rating );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue