khalil0525
Forum Replies Created
-
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.
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.