• Resolved khalil0525

    (@khalil0525)


    Hello, I’m having an issue with using the currency set by the yaycurrency with my products. I created a function to print out the current selected currency to the error log inside of the plugin that I’m using this with and at first a selected currency like “SGD” is printed followed by “USD”. This is happening after a page refresh. please refer to my posting here for more information.

    My goal is to be able to display the totals/subtotals of the items and cart using the currently set yaycurrency currency. Is there any specific hooks I can use to get the current set currency aside from woocommerce_currency?
    https://www.reddit.com/r/Wordpress/comments/17deq1k/yaycurrency_woocommerce_currency_bug/

    • This topic was modified 1 year, 1 month ago by khalil0525.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Bruce

    (@ninjateamwp)

    Hi @khalil0525,

    Thanks for coming today!

    Since this is a technical issue, you can reach our technical team here for help:

    yaycommerce.com/support

    Regards,
    Bruce

    Plugin Support mialewp

    (@mialewp)

    Hi @khalil0525,

    Good day!

    Thanks for your patience.

    Please try using this function to get the current selected currency

    Yay_Currency\Helpers\YayCurrencyHelper::detect_current_currency();

    Please test it again and let us know if it works.

    If you have any further questions, please feel free to contact us.

    Best regards,

    Mia

    Thread Starter khalil0525

    (@khalil0525)

    I was able to fix the main cart’s currency but I’m still having an issue with the cart drawer for the theme.

    When adding a non-custom item to the cart the cart drawer is triggered, but it is showing the item amount in USD and not the selected currency.

    function mfn_get_woo_sidecart_footer(){
    	//WC()->cart->calculate_totals();
    
    	$is_translatable = mfn_opts_get('translate');
    	$translate['translate-side-cart-shipping-free'] = $is_translatable ? mfn_opts_get('translate-side-cart-shipping-free', 'Free!') : __('Free!', 'woocommerce');
    
    	// output ---
    
    	echo '<div class="mfn-chft-row mfn-chft-subtotal">'.__( 'Subtotal', 'woocommerce' ).': '; wc_cart_totals_subtotal_html(); echo '</div>';
    	if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) :
    
    		$total = esc_html($translate['translate-side-cart-shipping-free']);
    
    	    if ( 0 < WC()->cart->get_shipping_total() ) {
    
    	      if ( WC()->cart->display_prices_including_tax() ) {
    	        $total = wc_price( WC()->cart->shipping_total + WC()->cart->shipping_tax_total );
    
    	        if ( WC()->cart->shipping_tax_total > 0 && ! wc_prices_include_tax() ) {
    	          $total .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
    	        }
    	      } else {
    	        $total = wc_price( WC()->cart->shipping_total );
    
    	        if ( WC()->cart->shipping_tax_total > 0 && wc_prices_include_tax() ) {
    	          $total .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
    	        }
    	      }
    	    }
    
    		echo '<div class="mfn-chft-row mfn-chft-row-shipping">'.__( 'Shipping', 'woocommerce' ).': <span>'. $total .'</span></div>';
    	endif;
    	echo '<div class="mfn-chft-row mfn-chft-total">'.__( 'Total', 'woocommerce' ).': '; wc_cart_totals_subtotal_html(); echo '</div>';
    }

    This seems to be the code controlling the shipping, subtotal and total. I changed the last line to fix an issue that was occurring in which the total was being calculated in USD. I’m not sure if this is a yaycurrency or theme related issue.

    We have a custom product that is generated by a custom plugin we made. When this custom product is finished generating in the custom backend it adds the item to cart and redirects to the /cart page.

    When a user adds a non-custom product then they are not redirected and instead the drawer opens and shows the items added, but in USD and not the selected currency. Upon refresh the correct data is shown for the totals.

    Plugin Support Bruce

    (@ninjateamwp)

    Hi @khalil0525,

    Let me consult our dev team again and I will get back to you soon!

    Regards,
    Bruce

    Thread Starter khalil0525

    (@khalil0525)

    Thanks Bruce!

    I have implemented some logging for this. To give some background, I’m a full-stack developer with node and python but am new to custom wordpress php. I am the second dev on this project so I do not know if these are hooks that are native to wordpress/woocommerce/theme but I can see in the output of the mf_frefreshsidecart() function that the currency is showing as “USD” when this refresh takes place.

    // fix for ajax & wcml
    add_filter( 'wcml_multi_currency_ajax_actions', 'mfn_add_action_to_multi_currency_ajax', 10, 1 );
    function mfn_add_action_to_multi_currency_ajax( $ajax_actions ) {
        $ajax_actions[] = 'mfnrefreshcart'; // Add a AJAX action to the array
        return $ajax_actions;
    }
    
    add_action( 'wp_ajax_mfnrefreshcart', 'mfn_refreshsidecart' );
    add_action( 'wp_ajax_nopriv_mfnrefreshcart', 'mfn_refreshsidecart' );
    
    function mfn_refreshsidecart(){
    	check_ajax_referer( 'mfn-woo-nonce', 'mfn-woo-nonce' );
    	$return = array();
    
    	/*if ( is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' ) ) {
    		$mc = \WCPay\MultiCurrency\MultiCurrency::instance();
    		$mc->init();
    	}*/
    $current_currency = get_woocommerce_currency();
    error_log('Current Currency - refresh: ' . $current_currency);
    
    
    	WC()->cart->calculate_totals();
    
    	ob_start();
    	mfn_get_woo_sidecart_content();
    	$return['content'] = ob_get_clean();
    
    	ob_start();
    	mfn_get_woo_sidecart_footer();
    	$return['footer'] = ob_get_clean();
    
    	$return['total'] = WC()->cart->get_cart_contents_count();
    
    	wp_send_json($return);
    	wp_die();
    }
    

    This occurs after add to cart for non-custom items.

    Plugin Support Bruce

    (@ninjateamwp)

    Hi @khalil0525,

    Thanks for the additional info.

    Our dev team would like to do more technical checking for you, please reach us here using any of the available support options:

    yaycommerce.com/support

    Regards,
    Bruce

    Plugin Support mialewp

    (@mialewp)

    Hi?@khalil0525,

    Good day!

    We have sent the fixed version to your email. Please test it again and let us know if it works.

    Looking forward to hearing back from you.

    Many thanks!

    Mia

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Woocomerce_currency defaulting to USD’ is closed to new replies.