首页 > 解决方案 > 使用 API 使用 javascript 转换货币

问题描述

我在 Wordpress 中构建了页面,并且在页面中有一个产品循环,它有多个值和

这是php循环:

<?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
      $args = array(
            'post_type' =>'product',
            'posts_per_page' => 24,
            'publish_status' => 'published',
            'paged' => $paged,
                );
                 $loop = new WP_Query( $args );
                 while ( $loop->have_posts() ) : $loop->the_post();             
             ?>
         <div class="col3">
          <div class="post">
             <div class="featured">
               <?php the_post_thumbnail(); ?>
             </div>

             <div class="title">
               <a href="<?php the_permalink(); ?>"
                 ><h3>
                   <?php the_title(); ?>
                 </h3></a
               >
             </div>
             <div class="categories">
                <?php echo get_the_term_list( $post->ID, 'products_cat', '<span> ', ', ', '</span> ' ); ?>
             </div>
              <?php if( get_field('brand') ): ?>
             <div class="brand">
               <span>Brand: <?php the_field('brand'); ?></span>
             </div>
            <?php endif; ?>  
              <?php if( get_field('modal') ): ?>
             <div class="modal">Model: <span><?php the_field('modal'); ?></span></div>
              <?php endif; ?>  
              <?php 
            if(have_rows('price') ):
            while (have_rows('price') ) : the_row();
            $flag = get_sub_field('flag');
        ?>
             <div class="prices">
               <h4><?php the_sub_field('title'); ?></h4>
   <?php 
            if(have_rows('prices') ):
            while (have_rows('prices') ) : the_row();
            $flag = get_sub_field('flag');
        ?>
          <div class="details">
            <div class="img"><img src="<?php switch($flag) {
                case 'Canada':
                        echo 'https://themoneysaver.co/wp-content/uploads/2021/03/canada-png.png';
                break;
                case 'Italy':
                        echo 'https://themoneysaver.co/wp-content/uploads/2021/03/1280px-Flag_of_Italy.svg.png';
                break;
                case 'France':
                        echo 'https://themoneysaver.co/wp-content/uploads/2021/03/1500px-Flag_of_France.svg.png';
                break;
                case 'United Kingdom':
                        echo 'https://themoneysaver.co/wp-content/uploads/2021/03/640px-Flag_of_the_United_Kingdom.svg.png';
                break;
                case 'Spain':
                        echo 'https://themoneysaver.co/wp-content/uploads/2021/03/spain-flag-png-large-1.jpg';
                break;
                case 'USA':
                        echo 'https://themoneysaver.co/wp-content/uploads/2021/03/Us_flag_large_38_stars.png';
                break;
        };?>" alt="" /></div>
                 <a href="<?php the_sub_field('link'); ?>" target="_blank">
                   <span class="price"><?php the_sub_field('sign'); ?></span>
                   <span class="shipping"><?php the_sub_field('original'); ?></span>+
                  <span><?php the_sub_field('plus'); ?></span>
            <?php if( get_sub_field('down') ): ?>
                   <span class="down"
                     >(<i class="fas fa-arrow-down"></i> <?php the_sub_field('down'); ?>)</span>
                <?php endif; ?>  
                   <span><i class="fas fa-external-link-alt"></i></span>
                 </a>
               </div>
                 <?php  endwhile;
                        endif; 
                  ?>
             </div>
              <?php  endwhile;
        endif; 

        ?>
            <?php if( get_field('discrption') ): ?>
             <div class="discription">
               <h4>Description</h4>
              <p>
                <?php the_field('discrption'); ?>
               </p>
             </div>
             <?php endif; ?>    
           </div>
         </div>
 <?php
        endwhile; 
        wp_reset_query();
        wp_reset_postdata();
    ?>

我正在使用ACF来获取额外的字段。我想将其转换为符号 + 价格 + 运费,默认为美元和。我想在 5 个国家/地区进行转换

标签: javascriptphphtmlwordpress

解决方案


推荐阅读