在购物车上显示复选框选择

时间:2018-05-14 23:23:40

标签: php forms checkbox methods get

我正在尝试在购物车中显示复选框选项,并使用表单中的$ GET方法将其显示在电子邮件中。

<label>
  <input type="checkbox" value="<?php echo esc_attr($food_group_ingredients_price); ?>" id="checks_<?php echo $counts; ?><?php the_id(); ?>"><?php echo esc_attr($food_group_ingredients_size); ?> <span>+ <?php if(isset($currency_menu) && !empty($currency_menu)){ echo esc_attr($currency_menu);}?><?php echo esc_attr($food_group_ingredients_price); ?></span>
</label>
<script type="text/javascript">
  jQuery(function($){ 
    $(document).ready(function() {

      $("input[id='checks_<?php echo $counts; ?><?php the_id(); ?>']").click(function(){

        if( $(this).is(':checked') ){ 
          var price3 = parseFloat($("#pricecase2-<?php the_id();?>").val());
          var price4 = parseFloat($("#checks_<?php echo $counts; ?><?php the_id(); ?>").val());
          var totalprices = ( price3 + price4 );

          $('span.price-<?php the_id();?> input#pricecase2-<?php the_id();?>').val(totalprices);  

          var price_latest1 = parseFloat($("#price-<?php the_id();?>").val());
          var price_latest2 = parseFloat($("#pricecase2-<?php the_id();?>").val());
          var price1 = parseFloat($("#testprice_<?php the_id(); ?>").val());
          var price_n = price_latest1 + ( price_latest2 - price1 );
          var price_latest_all = Math.round( price_n * 1000)/1000;

          $('span.price-<?php the_id();?> input#pricelatest-<?php the_id();?>').val( price_latest_all );
        }

      });

      $("input[id='checks_<?php echo $counts; ?><?php the_id(); ?>']").click(function(){
        if( !$(this).is(':checked')  ){
          var price3_after = parseFloat($("#pricecase2-<?php the_id();?>").val());
          var price4_after = parseFloat($("#checks_<?php echo $counts; ?><?php the_id(); ?>").val());
          var totalprices_after = ( price3_after - price4_after );

          $('span.price-<?php the_id();?> input#pricecase2-<?php the_id();?><?php echo esc_attr($food_group_ingredients_size); ?>').val(totalprices_after);

          var price_latest1 = parseFloat($("#price-<?php the_id();?>").val());
          var price_latest2 = parseFloat($("#pricecase2-<?php the_id();?>").val());
          var price1 = parseFloat($("#testprice_<?php the_id(); ?>").val());
          var price_n = price_latest1 + ( price_latest2 - price1 );
          var price_latest_all = Math.round( price_n * 1000)/1000;

          $('span.price-<?php the_id();?> input#pricelatest-<?php the_id();?>').val( price_latest_all );


        }
      });

    });
  });

</script>

**The Cart**
<table>
  <tbody  id="mycart">
  </tbody>
  <tbody  id="name_foodid">
  </tbody>
</table>
<hr>
<div class="row" id="options_2">

</div><!-- Edn options 2 -->
<label>
  <p class="fsize"><u>Hinweis:</u><br>
    Eine Lieferung ist erst ab einem Mindestbestellwert von 10€ innerhalb<br> Kaiserslauterns und 25€ ausserhalb von Kaiserslautern möglich.</p><br>

  <input type="radio" id="check" checked ="checked"  onclick = "Check1()" value=""  name="option_3">
  <?php echo esc_html__('Lieferung', 'quickfood' );?>

</label>
<!--<label>
<input type="radio" id="check1"  onclick = "Check2()" value=""  name="option_3">
<?php echo esc_html__('Take Away', 'quickfood' );?>
</label>-->
<hr>
<table class="table table_summary">
  <tbody>
    <tr>
      <td>
        <div class="cart-total"><?php echo esc_html__('Zwischensumme', 'quickfood');?> <em class="pull-right"><?php if(isset($currency_menu) && !empty($currency_menu)){ echo esc_attr($currency_menu);}else{}?><span>0</span></em>
          <input type="hidden" name="total-hidden-charges" id="total-hidden-charges" value="0" />
        </div>
      </td>
    </tr>
    <tr>
      <!--<td>
Delivery fee <span class="pull-right"><?php if(isset($currency_menu) && !empty($currency_menu)){ echo esc_attr($currency_menu);}else{}?><?php echo esc_attr($delivery_charge );?></span>
</td>-->
    </tr>
    <tr>
      <td class="total">
        <div class="cart-total2">GESAMT <em class="pull-right"><?php if(isset($currency_menu) && !empty($currency_menu)){ echo esc_attr($currency_menu);}else{}?>&nbsp;<span>0</span></em>
        </div>
      </td>
    </tr>
  </tbody>
</table>
<hr>
<form action="<?php if(isset($select_pages_checkout)){ echo get_page_link($select_pages_checkout); }else{echo "#";}?>" method="POST">
  <input type="hidden" name="id_menu"  id="id_menu" value="<?php echo get_the_ID();?>" />
  <input type="hidden" name="delivery_charge"  id="deliverry" value="<?php echo esc_attr($delivery_charge );?>" />
  <input type="hidden" name="total-hidden-charges2"  class="total-hidden-charges2" value="0" />
  <input type="hidden" name="check"  id="check-hidden" value="0" />
  <input type="hidden" name="phone-store"  id="phonenumber" value="<?php echo esc_attr($phone_number);?>" />
  <input type="hidden" name="working-period"  id="workingperiod" value="<?php echo esc_attr($working_period);?>" />
  <input type="hidden" name="arrprice"  id="arrprice" value="" />
  <input type="hidden" name="arrname"  id="arrname" value="" />
  <input type="hidden" name="number_quantity"  id="number_quantity" value="" />
  <button type="submit" class="btn_full"><?php echo esc_html__( 'Weiter zum bestellen', 'quickfood' );?></button>
</form>

</div><!-- End cart_box -->
</div><!-- End theiaStickySidebar -->
</div><!-- End col-md-3 -->

</div><!-- End row -->

**The form**

$name_buyer   = $_GET['name_buyer'];
$buyer_emails = $_GET['buyer_email'];
$price        = $_GET['price'];
$detailfood   = $_GET['detailfood'];
$currency     = $_GET['currency'];
$item_number  = $_GET['item_number'];
$food_group_ingredients_size  = $_GET['_cmb2_food_group_ingredients_size'];
$note        = $_GET['note'];
$body_email  = "<html><body><h2>".__('Neue Bestellung:', 'quickfood')."</h2>";
$body_email .= "<h4>".__('Folgendes wurde bestellt:', 'quickfood')."</h4>";
$body_email .= "<strong>Bestellnummer</strong>: ".$item_number."<br/>".            
"<strong>Käufer Email</strong>: ".$buyer_emails." <br/><strong>Buyer Information</strong>: <br/><strong>Address: ".$address_orders."</strong><br/>
<strong>Telefonnummer: ".$tel_order."</strong><br/><strong>Postal Code: ".$pcode_oders."</strong><br/><strong>Name: </strong>".$name_buyer."<br/>
  <strong>Delivery Day: ".$delivery_schedule_day."</strong><br/><strong> Delivery Time: ".$delivery_schedule_time."</strong><br/>
    <strong>Bestellung: </strong>".$detailfood."<br/>
      <strong>Weitere Zutaten: </strong>".$food_group_ingredients_size."<br/>
        <strong>Anmerkung: ".$note."</strong></html></body>";

$other_email = $theme_option['email_receive'];
$multiple_to_recipients = array($buyer_emails,$other_email);      

$subject = __('Order detail', 'quickfood');
$body    = $body_email;
$headers = __('From website', 'quickfood') . "\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

wp_mail($multiple_to_recipients, $subject, $body, $headers);

我想再次显示购物车内的成分,然后将信息发送到表格,保存并发送到我的邮箱。

先谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

以下是我最感兴趣的内容: 此行显示成分的名称:

<?php echo esc_attr($food_group_ingredients_size); ?>

所以我尝试将此行添加到此行:

if( $(this).is(':checked') ){ 
       var price3 = parseFloat($("#pricecase2-<?php the_id();?>").val());
       var price4 = parseFloat($("#checks_<?php echo $counts; ?><?php the_id(); ?><?php echo esc_attr($food_group_ingredients_size);?>").val());
       var totalprices = ( price3 + price4 );

但它显示了购物车内的NaN,而不是ingedient的名称+奖品。

以下是代码:

    <label>
  <input type="checkbox" value="<?php echo esc_attr($food_group_ingredients_price); ?>" id="checks_<?php echo $counts; ?><?php the_id(); ?>">*<?php echo esc_attr($food_group_ingredients_size); ?>* <span>+ <?php if(isset($currency_menu) && !empty($currency_menu)){ echo esc_attr($currency_menu);}?><?php echo esc_attr($food_group_ingredients_price); ?></span>
</label>
<script type="text/javascript">
  jQuery(function($){ 
    $(document).ready(function() {

      $("input[id='checks_<?php echo $counts; ?><?php the_id(); ?>']").click(function(){

        if( $(this).is(':checked') ){ 
          var price3 = parseFloat($("#pricecase2-<?php the_id();?>").val());
          var price4 = parseFloat($("#checks_<?php echo $counts; ?><?php the_id(); ?><?php echo esc_attr($food_group_ingredients_size); ?>").val());
          var totalprices = ( price3 + price4 );