WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WooCommerce] order-review.php shows wrong language (7 posts)

  1. vivaleces
    Member
    Posted 1 year ago #

    Hi,

    I'm using WooCommerce with two languages, English and Swedish.

    It translates everything fine, except for the order-review.php part on the checkout page.

    When I choose Swedish (Svenska) on the site it translates the order-review.php part to swedish, but only for a brief moment before it goes back to english - what could be wrong?

    Site: http://www.denniscessan.se/projekt/aws/sv/checkout/

    You need to add an item to the cart to see what I mean. :)

  2. vivaleces
    Member
    Posted 1 year ago #

    order-review.php

    <?php
    /**
     * Review order form
     *
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     1.6.4
     */
    
    global $woocommerce;
    
    $available_methods = $woocommerce->shipping->get_available_shipping_methods();
    ?>
    <div id="order_review">
    
    	<table class="shop_table">
    		<thead>
    			<tr>
    				<th class="product-name"><?php _e('Product', 'woocommerce'); ?></th>
    				<th class="product-quantity"><?php _e('Qty', 'woocommerce'); ?></th>
    				<th class="product-total"><?php _e('Totals', 'woocommerce'); ?></th>
    			</tr>
    		</thead>
    		<tfoot>
    
    			<tr class="cart-subtotal">
    				<th colspan="2"><strong><?php _e('Cart Subtotal', 'woocommerce'); ?></strong></th>
    				<td><?php echo $woocommerce->cart->get_cart_subtotal(); ?></td>
    			</tr>
    
    			<?php if ($woocommerce->cart->get_discounts_before_tax()) : ?>
    
    			<tr class="discount">
    				<th colspan="2"><?php _e('Cart Discount', 'woocommerce'); ?></th>
    				<td>-<?php echo $woocommerce->cart->get_discounts_before_tax(); ?></td>
    			</tr>
    
    			<?php endif; ?>
    
    			<?php if ( $woocommerce->cart->needs_shipping() && $woocommerce->cart->show_shipping() ) : ?>
    
    			<?php do_action('woocommerce_review_order_before_shipping'); ?>
    
    			<tr class="shipping">
    				<th colspan="2"><?php _e('Shipping', 'woocommerce'); ?></th>
    				<td>
    				<?php
    					// If at least one shipping method is available
    					if ( $available_methods ) {
    
    						// Prepare text labels with price for each shipping method
    						foreach ( $available_methods as $method ) {
    							$method->full_label = esc_html( $method->label );
    
    							if ( $method->cost > 0 ) {
    								$method->full_label .= ': ';
    
    								// Append price to label using the correct tax settings
    								if ( $woocommerce->cart->display_totals_ex_tax || ! $woocommerce->cart->prices_include_tax ) {
    									$method->full_label .= woocommerce_price( $method->cost );
    									if ( $method->get_shipping_tax() > 0 && $woocommerce->cart->prices_include_tax ) {
    										$method->full_label .= ' '.$woocommerce->countries->ex_tax_or_vat();
    									}
    								} else {
    									$method->full_label .= woocommerce_price( $method->cost + $method->get_shipping_tax() );
    									if ( $method->get_shipping_tax() > 0 && ! $woocommerce->cart->prices_include_tax ) {
    										$method->full_label .= ' '.$woocommerce->countries->inc_tax_or_vat();
    									}
    								}
    							}
    						}
    
    						// Print a single available shipping method as plain text
    						if ( 1 === count( $available_methods ) ) {
    
    							echo $method->full_label;
    							echo '<input type="hidden" name="shipping_method" id="shipping_method" value="'.esc_attr( $method->id ).'">';
    
    						// Show multiple shipping methods
    						} else {
    
    							if ( get_option('woocommerce_shipping_method_format') == 'select' ) {
    
    								echo '<select name="shipping_method" id="shipping_method">';
    
    								foreach ( $available_methods as $method )
    									echo '<option value="' . esc_attr( $method->id ) . '" ' . selected( $method->id, $_SESSION['_chosen_shipping_method'], false ) . '>' . strip_tags( $method->full_label ) . '</option>';
    
    								echo '</select>';
    
    							} else {
    
    								echo '<ul id="shipping_method">';
    
    								foreach ( $available_methods as $method )
    									echo '<li><input type="radio" name="shipping_method" id="shipping_method_' . sanitize_title( $method->id ) . '" value="' . esc_attr( $method->id ) . '" ' . checked( $method->id, $_SESSION['_chosen_shipping_method'], false) . ' /> <label for="shipping_method_' . sanitize_title( $method->id ) . '">' . $method->full_label . '</label></li>';
    
    								echo '</ul>';
    
    							}
    
    						}
    
    					// No shipping methods are available
    					} else {
    
    						if ( ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) {
    							echo '<p>'.__('Please fill in your details above to see available shipping methods.', 'woocommerce').'</p>';
    						} else {
    							echo '<p>'.__('Sorry, it seems that there are no available shipping methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce').'</p>';
    						}
    
    					}
    				?></td>
    
    			</tr>
    
    			<?php do_action('woocommerce_review_order_after_shipping'); ?>
    
    			<?php endif; ?>
    
    			<?php
    				if ($woocommerce->cart->get_cart_tax()) :
    
    					$taxes = $woocommerce->cart->get_formatted_taxes();
    
    					if (sizeof($taxes)>0) :
    
    						$has_compound_tax = false;
    
    						foreach ($taxes as $key => $tax) : if ($woocommerce->cart->tax->is_compound( $key )) : $has_compound_tax = true; continue; endif;
    
    							?>
    							<tr class="tax-rate tax-rate-<?php echo $key; ?>">
    								<th colspan="2"><?php
    									if ( get_option('woocommerce_prices_include_tax') == 'yes' )
    										_e('incl.&nbsp;', 'woocommerce');
    									echo $woocommerce->cart->tax->get_rate_label( $key );
    								?></th>
    								<td><?php echo $tax; ?></td>
    							</tr>
    							<?php
    
    						endforeach;
    
    						if ($has_compound_tax && !$woocommerce->cart->prices_include_tax) :
    							?>
    							<tr class="order-subtotal">
    								<th colspan="2"><strong><?php _e('Order Subtotal', 'woocommerce'); ?></strong></th>
    								<td><?php echo $woocommerce->cart->get_cart_subtotal( true ); ?></td>
    							</tr>
    							<?php
    						endif;
    
    						foreach ($taxes as $key => $tax) : if (!$woocommerce->cart->tax->is_compound( $key )) continue;
    
    							?>
    							<tr class="tax-rate tax-rate-<?php echo $key; ?>">
    								<th colspan="2"><?php
    									if ( get_option('woocommerce_prices_include_tax') == 'yes' )
    										_e('incl.&nbsp;', 'woocommerce');
    									echo $woocommerce->cart->tax->get_rate_label( $key );
    								?></th>
    								<td><?php echo $tax; ?></td>
    							</tr>
    							<?php
    
    						endforeach;
    
    					else :
    
    						?>
    						<tr class="tax">
    							<th colspan="2"><?php echo $woocommerce->countries->tax_or_vat(); ?></th>
    							<td><?php echo $woocommerce->cart->get_cart_tax(); ?></td>
    						</tr>
    						<?php
    
    					endif;
    				elseif ( get_option( 'woocommerce_display_cart_taxes_if_zero' ) == 'yes' ) :
    				?>
    
    					<tr class="tax">
    						<th colspan="2"><?php echo $woocommerce->countries->tax_or_vat(); ?></th>
    						<td><?php _ex( 'N/A', 'Relating to tax', 'woocommerce' ); ?></td>
    					</tr>
    
    				<?php
    				endif;
    			?>
    
    			<?php if ($woocommerce->cart->get_discounts_after_tax()) : ?>
    
    			<tr class="discount">
    				<th colspan="2"><?php _e('Order Discount', 'woocommerce'); ?></th>
    				<td>-<?php echo $woocommerce->cart->get_discounts_after_tax(); ?></td>
    			</tr>
    
    			<?php endif; ?>
    
    			<?php do_action('woocommerce_before_order_total'); ?>
    
    			<tr class="total">
    				<th colspan="2"><strong><?php _e('Order Total', 'woocommerce'); ?></strong></th>
    				<td><strong><?php echo $woocommerce->cart->get_total(); ?></strong></td>
    			</tr>
    
    			<?php do_action('woocommerce_after_order_total'); ?>
    
    		</tfoot>
    		<tbody>
    			<?php
    				if (sizeof($woocommerce->cart->get_cart())>0) :
    					foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
    						$_product = $values['data'];
    						if ($_product->exists() && $values['quantity']>0) :
    							echo '
    								<tr class = "' . esc_attr( apply_filters('woocommerce_checkout_table_item_class', 'checkout_table_item', $values, $item_id ) ) . '">
    									<td class="product-name">'.$_product->get_title().$woocommerce->cart->get_item_data( $values ).'</td>
    									<td class="product-quantity">'.$values['quantity'].'</td>
    									<td class="product-total">' . apply_filters( 'woocommerce_checkout_item_subtotal', $woocommerce->cart->get_product_subtotal( $_product, $values['quantity'] ), $values, $item_id ) . '</td>
    								</tr>';
    						endif;
    					endforeach;
    				endif;
    
    				do_action( 'woocommerce_cart_contents_review_order' );
    			?>
    		</tbody>
    	</table>
    
    	<div id="payment">
    		<?php if ($woocommerce->cart->needs_payment()) : ?>
    		<ul class="payment_methods methods">
    			<?php
    				$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
    				if ($available_gateways) :
    					// Chosen Method
    					if (sizeof($available_gateways)) :
    						$default_gateway = get_option('woocommerce_default_gateway');
    						if (isset($_SESSION['_chosen_payment_method']) && isset($available_gateways[$_SESSION['_chosen_payment_method']])) :
    							$available_gateways[$_SESSION['_chosen_payment_method']]->set_current();
    						elseif (isset($available_gateways[$default_gateway])) :
    							$available_gateways[$default_gateway]->set_current();
    						else :
    							current($available_gateways)->set_current();
    						endif;
    					endif;
    					foreach ($available_gateways as $gateway ) :
    						?>
    						<li>
    						<input type="radio" id="payment_method_<?php echo $gateway->id; ?>" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php if ($gateway->chosen) echo 'checked="checked"'; ?> />
    						<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
    							<?php
    								if ( $gateway->has_fields() || $gateway->get_description() ) :
    									echo '<div class="payment_box payment_method_'.$gateway->id.'" style="display:none;">';
    									$gateway->payment_fields();
    									echo '</div>';
    								endif;
    							?>
    						</li>
    						<?php
    					endforeach;
    				else :
    
    					if ( !$woocommerce->customer->get_country() ) :
    						echo '<p>'.__('Please fill in your details above to see available payment methods.', 'woocommerce').'</p>';
    					else :
    						echo '<p>'.__('Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce').'</p>';
    					endif;
    
    				endif;
    			?>
    		</ul>
    		<?php endif; ?>
    
    		<div class="form-row place-order">
    
    			<noscript><?php _e('Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce'); ?><br/><input type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php _e('Update totals', 'woocommerce'); ?>" /></noscript>
    
    			<?php $woocommerce->nonce_field('process_checkout')?>
    
    			<?php do_action( 'woocommerce_review_order_before_submit' ); ?>
    
    			<input type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="<?php echo apply_filters('woocommerce_order_button_text', __('Place order', 'woocommerce')); ?>" />
    
    			<?php if (woocommerce_get_page_id('terms')>0) : ?>
    			<p class="form-row terms">
    				<label for="terms" class="checkbox"><?php _e('I accept the', 'woocommerce'); ?> <a href="<?php echo esc_url( get_permalink(woocommerce_get_page_id('terms')) ); ?>" target="_blank"><?php _e('terms & conditions', 'woocommerce'); ?></a></label>
    				<input type="checkbox" class="input-checkbox" name="terms" <?php if (isset($_POST['terms'])) echo 'checked="checked"'; ?> id="terms" />
    			</p>
    			<?php endif; ?>
    
    			<?php do_action( 'woocommerce_review_order_after_submit' ); ?>
    
    		</div>
    
    		<div class="clear"></div>
    
    	</div>
    
    </div>

    Let me know if you need anything else?

    Thank you! :)

  3. sickmind
    Member
    Posted 1 year ago #

    We have encountered the same problem, and we think it´s because of the handling of chosen language and ajax.

    The lang parameters isn´t get through the default ajax call.

  4. sardbaba
    Member
    Posted 1 year ago #

    @sickmind you are right. The incriminated code is:

    xhr = $.ajax({
      type: 'POST',
      url: 	woocommerce_params.ajax_url,
      data: data,
      success: function( response ) {
        if ( response ) {
          var order_output = $(response);
          $('#order_review').html(order_output.html());
    	$('body').trigger('updated_checkout');
        }
      }
    });

    into assets/js/fronted/checkout.js

    Actually, it loads the min version, but you can rename checkout.min.js into checkout.min.orig.js, then copy the full version - checkout.js - and rename it in checkout.min.js so you can modify it directly and see the changes.

  5. sardbaba
    Member
    Posted 1 year ago #

    This experimental plugin http://www.somewherewarm.net/apps/woocommerce-qtml/ seems to solves the problem. Purchased right now and it works.

  6. zelkovawebstudio
    Member
    Posted 9 months ago #

    Hi there!

    I got the same problem but, sincerely, I bought woocommerce qtml and solved my problem.

    It's a mess trying to edit ajax callback functions on order-review.php, and I've been working with woocommerce and WP a lot of time. So I decided to buy the plugin, it's only 9$ and will save your ass for a long time.

    BUT, there's something now that I don't understand:

    On the same order-review section, my shipping method is not changing when I select a different country from the billing or shipping form. It's weird, but only when I check the "send to billing address" checkbox, the shipping method is updating and getting ok.

    Does anyone messed with that before? It's not about a plugin, or something, because I've disabled them all and it's behaving that way again.

    Thank you so much!!

  7. zelkovawebstudio
    Member
    Posted 9 months ago #

    Oh, ok, sorry about the last part of my message. It's working fine so let's code again.
    Thank you all anyway!!
    :)

Topic Closed

This topic has been closed to new replies.

About this Topic