function parseJsonToArray( $url ){
return json_decode( file_get_contents( $url ), true);
}
function makeTextIndex( $string ) {
return strtoupper(
preg_replace(
'/[^a-zA-Z0-9_-]/',
'',
str_replace(" ", "_", $string )
)
);
}
$countries = parseJsonToArray('https://raw.githubusercontent.com/Genri-Rus/Json/master/countries.json');
$regions = parseJsonToArray('https://raw.githubusercontent.com/Genri-Rus/Json/master/region.json');
$result_countries = [];
$result_regions = [];
foreach ($countries as $country){
$country_text_index = makeTextIndex( $country['title_en'] );
$result_countries[ $country_text_index ] = $country['title_ru'];
}
foreach ($regions as $region){
$region_text_index = makeTextIndex( $region['title_en'] );
$result_regions[ $region_text_index ] = $region['title_ru'];
}
add_filter( 'woocommerce_countries', 'filter_function_name_6672' );
function filter_function_name_6672( $include ){
$include = '';
foreach ($result_countries as $key => $result_country) {
$include[$key] = [ $result_country ];
}
return include;
}
add_filter( 'woocommerce_states', 'new_rus_woocommerce_states' );
function new_rus_woocommerce_states( $states ) {
foreach ($result_regions as $key => $result_region) {
$states[$key] = [ $result_region ];
}
return $states;
}
<ul id="shipping_method" class="woocommerce-shipping-methods">
<?php foreach ( $available_methods as $method ) : ?>
<li>
<?php
if ( 1 < count( $available_methods ) ) {
printf( '<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ), checked( $method->id, $chosen_method, false ) ); // WPCS: XSS ok.
} else {
printf( '<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />', $index, esc_attr( sanitize_title( $method->id ) ), esc_attr( $method->id ) ); // WPCS: XSS ok.
}
printf( '<label for="shipping_method_%1$s_%2$s">%3$s</label>', $index, esc_attr( sanitize_title( $method->id ) ), wc_cart_totals_shipping_method_label( $method ) ); // WPCS: XSS ok.
do_action( 'woocommerce_after_shipping_rate', $method, $index );
?>
</li>
<?php endforeach; ?>
</ul>
$discount_total = 0;
$items = WC()->cart->get_cart();
foreach ( $items as $cart_item_key => $values) {
//
}
<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
<div class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
<span><?php wc_cart_totals_coupon_label( $coupon ); ?></span>
<span data-title="<?php echo esc_attr( wc_cart_totals_coupon_label( $coupon, false ) ); ?>"><?php wc_cart_totals_coupon_html( $coupon ); ?></span>
</div>
<?php endforeach; ?>
<?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
<div class="fee">
<span><?php echo esc_html( $fee->name ); ?></span>
<span data-title="<?php echo esc_attr( $fee->name ); ?>"><?php wc_cart_totals_fee_html( $fee ); ?></span>
</div>
<?php endforeach; ?>
$items = WC()->cart->get_cart();
<span class="order-info-sale">
<?php
$discount_total = 0;
foreach ( $items as $cart_item_key => $values) {
$_product = $values['data'];
if ( $_product->is_on_sale() ) {
$regular_price = $_product->get_regular_price();
$sale_price = $_product->get_sale_price();
$discount = ($regular_price - $sale_price) * $values['quantity'];
$discount_total += $discount;
}
}
if ( $discount_total > 0 ) {
echo number_format($discount_total + WC()->cart->discount_cart, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() );
}
?>
</span>
WC_Product_Attribute Object ( [data:protected] => Array ( [id] => 1 [name] => pa_brendy [options] => Array ( [0] => 30 ) [position] => 0 [visible] => [variation] => ) ) WC_Product_Attribute Object ( [data:protected] => Array ( [id] => 2 [name] => pa_tsveta [options] => Array ( [0] => 32 ) [position] => 1 [visible] => [variation] => ) )
Но в таком случае страны в зонах доставки пропадают
Если добавить только 2 символа, то все работает:
Но тогда проблема - повторяющие слова перезаписываются, может как-то рандом произвести над строками ?
Допустим:
"title_en": "US Virgin Islands"
И просто США
"title_en": "USA"
В итоге США перезаписывается