Reply To: Support for WCML

#13625

Jie
Participant
add_filter('asp_results', 'asp_display_price_w_currency', 10, 4);
function asp_display_price_w_currency($results, $sid, $is_ajax, $args) {
  if ( empty($args['woo_currency']) )
    return $results;
  global $woocommerce;
  global $sitepress;
  global $woocommerce_wpml;
  $currency = $args['woo_currency']; // GET THIS FROM A PARAM

  foreach ($results as $k=>&$r) {
    if ( isset($r->post_type) &&
         in_array($r->post_type, array('product', 'product_variation'))
    ) {
      $p = wc_get_product( $r->id );
      $price = $woocommerce_wpml->multi_currency->prices->get_product_price_in_currency( $r->id, $currency );
      $r->title .= ' – ' . wc_price($price, array('currency' => $currency));
    }
  }
  return $results;
}