• Resolved Filipe Costa

    (@filipecostacom)


    Hi there!

    Great Ajax search plugin!

    How can i display woocommerce products price on search results?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi!

    Thank you very much for your kind words!

    With a custom code it is actually possible. Try adding this custom code to the functions.php file in your theme/child theme directory.

    Please have a full site back-up via FTP before making any changes in your site files!!

    add_filter('asl_results', 'asl_display_price_w_currency', 10, 4);
    function asl_display_price_w_currency($results, $sid, $is_ajax, $args) {
      global $woocommerce;
      global $sitepress;
      global $woocommerce_wpml;  
      $currency = isset($args['woo_currency']) ? 
        $args['woo_currency'] : 
        function_exists('get_woocommerce_currency') ? 
          get_woocommerce_currency() : '';
      
      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 );
          if ( isset($woocommerce_wpml, $woocommerce_wpml->multi_currency) )
            $price = $woocommerce_wpml->multi_currency->prices->get_product_price_in_currency( $r->id, $currency );
          else
            $price = $p->get_price();
          if ( $currency != '' )
            $price = wc_price($price, array('currency' => $currency));
          else
            $price = wc_price($price);
          $r->title .= ' - ' . $price;
        }
      }
      return $results;
    }
    Thread Starter Filipe Costa

    (@filipecostacom)

    Excellent! Thank you very much!

    Hope you can add this option to the plugin on a future update ??

    Plugin Author wpdreams

    (@wpdreams)

    You are very welcome! I will try to figure out something for this in the future.

    Feel free to rate the plug-in, it’s greatly appreciated. Let me know if you find any other issues.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display WooCommerce price on results’ is closed to new replies.