2012-08-07 40 views
1

我試圖根據我的客戶的需求調整Wordpress Jigoshop,我有點卡住了。我需要的是:當選擇產品變體時,一些其他選項以客戶必須選擇的單選按鈕的形式出現。我設法讓所有的東西都能正常工作,但我現在需要的是當點擊提交按鈕時,將選定的單選按鈕發送到購物車,結賬等。試圖發送一個隱藏的輸入值到下一頁

我試圖用自己的產品定製功能來做到這一點,它們的功能是:

if (!function_exists('jigoshop_product_customize_panel')) { 
    function jigoshop_product_customize_panel() { 
     global $_product; 

    if (isset($_POST['Submit']) && $_POST['Submit'] == 'Save Personalization') { 
     $custom_products = (array) jigoshop_session::instance()->customized_products; 
     $custom_products[$_POST['customized_id']] = trim(wptexturize($_POST['jigoshop_customized_product'])); 
     jigoshop_session::instance()->customized_products = $custom_products; 
    } 

    if (get_post_meta($_product->ID , 'customizable', true) == 'yes') : 
     $custom_products = (array) jigoshop_session::instance()->customized_products; 
     $custom = isset($custom_products[$_product->ID]) ? $custom_products[$_product->ID] : ''; 
     $custom_length = get_post_meta($_product->ID , 'customized_length', true); 
     $length_str = $custom_length == '' ? '' : sprintf(__('You may enter a maximum of %s characters.', 'jigoshop'), $custom_length); 

     echo '<div class="panel" id="tab-customize">'; 
     echo '<p>' . apply_filters('jigoshop_product_customize_heading', __('Enter your personal information as you want it to appear on the product.<br />'.$length_str, 'jigoshop')) . '</p>'; 

     ?> 

      <form action="" method="post"> 

       <input type="hidden" name="customized_id" value="<?php echo esc_attr($_product->ID); ?>" /> 

       <?php 
       if ($custom_length == '') : 
       ?> 
        <textarea 
         id="jigoshop_customized_product" 
         name="jigoshop_customized_product" 
         cols="60" 
         rows="4"><?php echo esc_textarea($custom); ?> 
        </textarea> 
       <?php else : ?> 
        <input 
         type="text" 
         id="jigoshop_customized_product" 
         name="jigoshop_customized_product" 
         size="<?php echo $custom_length; ?>" 
         maxlength="<?php echo $custom_length; ?>" 
         value="<?php echo esc_attr($custom); ?>" /> 
       <?php endif; ?> 

       <p class="submit"><input name="Submit" type="submit" class="button-alt add_personalization" value="<?php _e("Save Personalization", 'jigoshop'); ?>" /></p> 

      </form> 

     <?php 
     echo '</div>'; 
    endif; 
} 
} 

我試圖改變它們的功能,以滿足我的需求,這是我想出(其中get_cod是id和隱藏輸入的名稱和「Adauga在COS」是我的提交按鈕的值):

if (!function_exists('salveaza_cod_material')) { 
function salveaza_cod_material() { 
    global $_product; 

    if (isset($_POST['submit']) && $_POST('submit') == 'Adauga in cos') { 
     $custom_products = (array) jigoshop_session::instance()->customized_products; 
     $custom_products[$_POST['customized_id']] = trim(wptexturize($_POST['get_cod'])); 
     jigoshop_session::instance()->customized_products = $custom_products; 
    } 

     $custom_products = (array) jigoshop_session::instance()->customized_products; 
     $custom = isset($custom_products[$_product->ID]) ? $custom_products[$_product->ID] : ''; 
}} 

但是價值不被髮送到下一個頁面。任何人都可以幫忙嗎?乾杯!

下面是一個包含多個代碼的更新:

<form action="<?php echo esc_url($_product->add_to_cart_url()); ?>"  class="variations_form cart" method="post"> 
     <fieldset class="variations"> 
      <?php foreach ($attributes as $name => $options): ?> 
       <?php $sanitized_name = sanitize_title($name); ?> 
       <div> 
        <span class="select_label"><?php echo jigoshop_product::attribute_label('pa_'.$name); ?></span> 

        <select id="<?php echo esc_attr($sanitized_name); ?>" name="tax_<?php echo $sanitized_name; ?>"> 

         <option value=""><?php echo __('Choose an option ', 'jigoshop') ?>&hellip;</option> 
         <?php foreach ($options as $value) : ?> 
          <?php if (taxonomy_exists('pa_'.$sanitized_name)) : ?> 
           <?php $term = get_term_by('slug', $value, 'pa_'.$sanitized_name); ?> 
           <option value="<?php echo esc_attr($term->slug); ?>"><?php echo $term->name; ?> </option> 
          <?php else : ?> 
           <option value="<?php echo esc_attr(sanitize_title($value)); ?>"><?php echo $value; ?></option> 
          <?php endif;?> 
         <?php endforeach; ?> 
        </select> 


       </div> 
      <?php endforeach;?> 
     </fieldset> 
<div id="piele-neagra" class="colors" style="display:none"> 
    <ul class="materiale"> 
    <li><input type="radio" name="piele-neagra" value="L73"> 
    <p><img class="alignnone size-full wp-image-155" title="L73" src="http://www.scaune-directoriale.ro/wp-content/uploads/materiale/piele-neagra/L73.gif" alt="L73" width="72" height="72" /></p> 
    </li> 
    </ul> 
</div> 

<div id="stofa-mf" class="colors" style="display:none"> 
    <ul class="materiale"> 

    <li><input type="radio" name="tapiterie" value="MF01" /> 


... 


<div id="stofa-rg" class="colors" style="display:none"> Stofa RG</div> 
     <div class="clear"></div> 

     <span id="cod_material"><?php echo esc_attr($custom); ?></span> 
     <span><?php echo trim(wptexturize($_POST['get_cod'])); ?></span> 
     <div class="single_variation"></div> 





     <?php do_action('jigoshop_before_add_to_cart_form_button'); ?> 
     <div class="variations_button" style="display:none;"> 
      <input type="hidden" name="variation_id" value="" /> 
      <input type="hidden" name="customized_id" value="<?php echo esc_attr($_product->ID); ?>" /> 
     <input type="hidden" id="get_cod" name="get_cod" value="" /> 
      <input type="hidden" name="product_id" value="<?php echo esc_attr($post->ID); ?>" /> 
      <div class="quantity"><input name="quantity" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div> 
      <input type="submit" id="submit_cart" class="button-alt" value="<?php esc_html_e('Add to cart', 'jigoshop'); ?>" /> 
     </div> 
     <?php do_action('salveaza_cod_material'); ?> 
     <?php do_action('jigoshop_add_to_cart_form'); ?> 
    </form> 

這是車的接收值的部分:

if (!empty($values['variation_id'])) { 
              $product_id = $values['variation_id']; 
            } else { 
             $product_id = $values['product_id']; 
            } 
             $custom_products = (array) jigoshop_session::instance()->customized_products; 
            $custom =  isset($custom_products[$product_id]) ? $custom_products[$product_id] : ''; 
            if (!  empty($custom_products[$product_id])) : 
             ?> 
             <dl  class="customization"> 
               <dt class="customized_product_label"><?php echo  apply_filters('jigoshop_customized_product_label', __('Personal: ','jigoshop')); ?></dt> 
               <dd class="customized_product"><?php echo esc_textarea($custom); ?></dd> 
              </dl> 
             <? php 
            endif; 
            ?> 
+0

首先,你是否嘗試用'type =「text」'替換'type =「hidden」'來查看'<?php echo esc_attr($ _produ ct-> ID); ?>'? – maxdec 2012-08-07 10:18:01

+0

嗨,謝謝你的回覆!它打印得很好(我用螢火蟲檢查過)。 – 2012-08-07 11:19:13

回答

0

這只是一個錯字:在if (isset($_POST['submit']) && $_POST('submit') == 'Adauga in cos'),更換$_POST('submit')通過$_POST['submit']

+0

我可能在我的一次嘗試中寫錯了。我糾正了它,它仍然不會發送。 – 2012-08-07 12:42:01

+0

隱藏輸入「get_cod」在哪裏? – maxdec 2012-08-07 14:42:26

+0

它與提交按鈕的形式相同。如果你想我可以發佈整個代碼,但它很大 – 2012-08-07 14:54:56

相關問題