Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP OOP foreach help

This is a short question, but I want to give you as much of the code as I can.  The first piece, below, is showing each item that has been entered into a shopping cart.
<?php


foreach ( $cart_items as $key => $item ) : ?>
	<tr class="edd_cart_item" id="edd_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-download-id="<?php echo esc_attr( $item['id'] ); ?>">
		<?php do_action( 'edd_checkout_table_body_first', $item ); ?>
		<td class="edd_cart_item_name">
			<?php
				echo '<span class="edd_checkout_cart_item_title">' . esc_html( $item_title ) . '</span>';
			?>
		</td>
		<td class="edd_cart_item_price"><?php echo edd_cart_item_price( $item['id'], $item['options'] ); ?></td>
		<td class="edd_cart_actions">
			<a href="<?php echo esc_url( edd_remove_item_url( $key, $post ) ); ?>"><?php _e( 'Remove', 'edd' ); ?></a>
		</td>
		<td>
			<?php 
				$custom = new customize();
				$custom->customButton($item);
			?>
		</td>			
		</tr>
		<tr>
		<!--  ADD CUSTOM FEAATURE  -->
			<td colspan="4">
				<?php 
					$custom->customizing($item, $id);
				?>
			</td>
		<!--  END CUSTOM FEAATURE  -->	
		</tr>
		
	<?php endforeach; ?>

Open in new window

With the function: $custom->customizing($item, $id);
I have added  three different color picker options, that can be added to the item purchased.

The following are all of the functions:
error_reporting( E_ALL );

class customize	{

	function customizing($item, $id)	{
		?>	
<div id='custom-hidden'>
<div class="change-logo-cont">
	<div style="width:50px;padding-top:5px; padding-bottom:5px; padding-right:10px;float:left;">
		<span>
		<label for="selectYesEditColor">Yes</label><input id="selectYesEditColor" type="radio" value="logo_color_yes" name="edit_color_group" onclick="ShowColorEditor();"/>
		
		</span>
	</div>
	<div style="width:50px;padding-top:5px; padding-bottom:5px;float:left;" >
		<span>
		<label for="selectNoEditColor">No</label><input id="selectNoEditColor" type="radio" name="edit_color_group" value="logo_color_no" checked="checked" onclick="HideColorEditor();"/>
		
		</span>
	</div>

</div>
<div id="show_color_option">
	
	
<div class="custom-color-picker-cont">
		
	<?php
		$this->customColorFieldOne($id);
	?>
<!--  END FIRST HIDDEN COLOR PICKER  -->	
	
	<?php
		$this->customColorFieldTwo();
	?>
<!--  END SECOND HIDDEN COLOR PICKER  -->

	<?php
		$this->customColorFieldThree();
	?>
<!--  END THIRD HIDDEN COLOR PICKER  -->		

	</div>
<!--  END SHOW COLOR OPTION  -->

</div>
<!--  END CUSOM COLOR  -->
<?php		
	}
	
	

function customColorFieldOne($id)	{
	?>
<div class="custom-color-pick-one">

	<table>
		<tr>
			<td width="150px"><span >pick color 1</span>
				<input type="checkbox" value="custom-color" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
				</td>
				<td width="300"><span>please specify which color to change</span>
				<input type="text" name="color-picker-comment" value="<?php if(isset($_POST['color-picker-comment'])) { echo $_POST['color-picker-comment'];}?>" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
				</td>
			</tr>
	</table>
</div>
			
<!--  START FIRST HIDDEN COLOR PICKER  -->
<div id="custom-color-1">
				<div id="color_pic_cont">
		
		<!--  SUN  -->
				<div class="custom-color-sun"><span class="custom-color-lrg">110</span><br />
					<span class="custom-color-sml">SUN &nbsp;&nbsp;
						<input type="radio" name="<?php echo $id; ?>-color-picker" class="color-picker" value="sun" <?php if(isset($_POST['color-picker']) && $_POST['color-picker'] == "sun"){ echo 'selected="selected"';}?> <?php if(isset($_POST['color-picker']) && $_POST['color-picker'] == "sun"){ echo 'selected="selected"';}?>/></span>
				</div>
		
		<!--  GOLD  -->
				<div class="custom-color-gold"><span class="custom-color-lrg">131</span><br />
					<span class="custom-color-sml">GOLD &nbsp;&nbsp;
						<input type="radio" name="color-picker" class="color-picker" value="gold" <?php if(isset($_POST['color-picker']) && $_POST['color-picker'] == "gold"){ echo 'selected="selected"';}?>/></span>
				</div>
				
		<!--  CHOCOLATE  -->
				<div class="custom-color-chocolate"><span class="custom-color-lrg">7568</span><br />
					<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
						<input type="radio" name="color-picker" class="color-picker" value="chocolate" <?php if(isset($_POST['color-picker']) && $_POST['color-picker'] == "chocolate"){ echo 'selected="selected"';}?>/></span>
				</div>								
												
				  <input type="checkbox" value="done choosing one"/>::  Done Choosing First Color
				</div>
</div>
<div class="clear"></div>
<?php
}



function customColorFieldTwo()	{
	?>
<div class="custom-color-pick-two">

	<table>
		<tr>
			<td width="150px"><span >pick color 2</span>
				<input type="checkbox" value="custom-color-2" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
				</td>
				<td width="300"><span>please specify which color to change</span>
				<input type="text" name="color-picker-comment-2" value="<?php if(isset($_POST['color-picker-comment-2'])) { echo $_POST['color-picker-comment-2'];}?>" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
				</td>
			</tr>
	</table>
</div>
			
<!--  START FIRST HIDDEN COLOR PICKER  -->
<div id="custom-color-2">
				<div id="color_pic_cont">
		
		<!--  SUN  -->
				<div class="custom-color-sun"><span class="custom-color-lrg">110</span><br />
					<span class="custom-color-sml">SUN &nbsp;&nbsp;
						<input type="radio" name="color-picker-2" class="color-picker" value="sun" <?php if(isset($_POST['color-picker-2']) && $_POST['color-picker-2'] == "sun"){ echo 'selected="selected"';}?> <?php if(isset($_POST['color-picker-2']) && $_POST['color-picker-2'] == "sun"){ echo 'selected="selected"';}?>/></span>
				</div>
		
		<!--  GOLD  -->
				<div class="custom-color-gold"><span class="custom-color-lrg">131</span><br />
					<span class="custom-color-sml">GOLD &nbsp;&nbsp;
						<input type="radio" name="color-picker-2" class="color-picker" value="gold" <?php if(isset($_POST['color-picker-2']) && $_POST['color-picker-2'] == "gold"){ echo 'selected="selected"';}?>/></span>
				</div>
				
		<!--  CHOCOLATE  -->
				<div class="custom-color-chocolate"><span class="custom-color-lrg">7568</span><br />
					<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
						<input type="radio" name="color-picker-2" class="color-picker" value="chocolate" <?php if(isset($_POST['color-picker-2']) && $_POST['color-picker-2'] == "chocolate"){ echo 'selected="selected"';}?>/></span>
				</div>
																
				  <input type="checkbox" value="done choosing two"/>::  Done Choosing Second Color
				</div>
</div>
<div class="clear"></div>
<?php
}



function customColorFieldThree()	{
	?>
<div class="custom-color-pick-three">

	<table>
		<tr>
			<td width="150px"><span >pick color 3</span>
				<input type="checkbox" value="custom-color-3" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
				</td>
				<td width="300"><span>please specify which color to change</span>
				<input type="text" name="color-picker-comment-3" value="<?php if(isset($_POST['color-picker-comment-3'])) { echo $_POST['color-picker-comment-3'];}?>" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
				</td>
			</tr>
	</table>
</div>
			
<!--  START FIRST HIDDEN COLOR PICKER  -->
<div id="custom-color-3">
				<div id="color_pic_cont">
		
		<!--  SUN  -->
				<div class="custom-color-sun"><span class="custom-color-lrg">110</span><br />
					<span class="custom-color-sml">SUN &nbsp;&nbsp;
						<input type="radio" name="color-picker-3" class="color-picker" value="sun" <?php if(isset($_POST['color-picker-3']) && $_POST['color-picker-3'] == "sun"){ echo 'selected="selected"';}?> <?php if(isset($_POST['color-picker-3']) && $_POST['color-picker-3'] == "sun"){ echo 'selected="selected"';}?>/></span>
				</div>
		
		<!--  GOLD  -->
				<div class="custom-color-gold"><span class="custom-color-lrg">131</span><br />
					<span class="custom-color-sml">GOLD &nbsp;&nbsp;
						<input type="radio" name="color-picker-3" class="color-picker" value="gold" <?php if(isset($_POST['color-picker-3']) && $_POST['color-picker-3'] == "gold"){ echo 'selected="selected"';}?>/></span>
				</div>
				
		<!--  CHOCOLATE  -->
				<div class="custom-color-chocolate"><span class="custom-color-lrg">7568</span><br />
					<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
						<input type="radio" name="color-picker-3" class="color-picker" value="chocolate" <?php if(isset($_POST['color-picker-3']) && $_POST['color-picker-3'] == "chocolate"){ echo 'selected="selected"';}?>/></span>
				</div>
													
				  <input type="checkbox" value="done choosing three"/>::  Done Choosing Third Color
				</div>
</div>
}

}


function store_custom_fields($payment_meta) {
	$payment_meta['color_picker'] = isset( $_POST['color-picker'] ) ? sanitize_text_field( $_POST['color-picker'] ) : '';
	$payment_meta['color_picker_comment'] = isset( $_POST['color-picker-comment'] ) ? sanitize_text_field( $_POST['color-picker-comment'] ) : '';
	$payment_meta['color_picker_2'] = isset( $_POST['color-picker-2'] ) ? sanitize_text_field( $_POST['color-picker-2'] ) : '';
	$payment_meta['color_picker_comment_2'] = isset( $_POST['color-picker-comment-2'] ) ? sanitize_text_field( $_POST['color-picker-comment-2'] ) : '';
	$payment_meta['color_picker_3'] = isset( $_POST['color-picker-3'] ) ? sanitize_text_field( $_POST['color-picker-3'] ) : '';
	$payment_meta['color_picker_comment_3'] = isset( $_POST['color-picker-comment-3'] ) ? sanitize_text_field( $_POST['color-picker-comment-3'] ) : '';
	return $payment_meta;
}
add_filter('edd_payment_meta', 'store_custom_fields');


// show the custom fields in the "View Order Details" popup
function custom_purchase_details($payment_meta, $user_info) {
	$color_picker  = isset( $payment_meta['color_picker'] ) ? $payment_meta['color_picker'] : 'none';
	$color_picker_comment  = isset( $payment_meta['color_picker_comment'] ) ? $payment_meta['color_picker_comment'] : 'none';
	$color_picker_2  = isset( $payment_meta['color_picker_2'] ) ? $payment_meta['color_picker_2'] : 'none';
	$color_picker_comment_2  = isset( $payment_meta['color_picker_comment_2'] ) ? $payment_meta['color_picker_comment_2'] : 'none';
	$color_picker_3  = isset( $payment_meta['color_picker_3'] ) ? $payment_meta['color_picker_3'] : 'none';
	$color_picker_comment_3  = isset( $payment_meta['color_picker_comment_3'] ) ? $payment_meta['color_picker_comment_3'] : 'none';
	?>
	<?php 
		if(isset($color_picker) || isset($color_picker_2) || isset($color_picker_3)) { ?>
	<li><?php echo __('<b>Color Picker One:</b>', 'pippin_edd') . ' ' . $color_picker; ?></li>
	<li><?php echo __('<b>Color One Comment:</b><br />', 'pippin_edd') . ' ' . $color_picker_comment; ?></li>
	<li><?php echo __('<b>Color Picker Two :</b>', 'pippin_edd') . ' ' . $color_picker_2; ?></li>
	<li><?php echo __('<b>Color Two Comment:</b><br />', 'pippin_edd') . ' ' . $color_picker_comment_2; ?></li>
	<li><?php echo __('<b>Color Picker Three:</b>', 'pippin_edd') . ' ' . $color_picker_3; ?></li>
	<li><?php echo __('<b>Color Three Comment:</b><br />', 'pippin_edd') . ' ' . $color_picker_comment_3; ?></li>
	<?php } ?>
	<?php
	mailIt($payment_meta, $user_info);
}
add_action('edd_payment_personal_details_list', 'custom_purchase_details', 10, 2);

Open in new window


It seems that It will work with one item but It won't work for two.
Meaning it enters all of the information for the first item, but it does not work in the foreach. It just uses the first info for the second info.  
So if I enter a color code, in the first foreach, the first item, It won't work on the second item.

Also, in the last function function custom_purchase_details($payment_meta, $user_info)
I don't know how to add each different item dynamically.

Any help will be appreciated.
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

When you've got a foreach that's not working, it often helps to dump the contents of the array you're working with, using print_r(). If it's inconvenient to output the information to screen, it might be more convenient to output the information to a log file of your choice:
 file_put_contents($filename, print_r($my_array, true), FILE_APPEND);

If you can provide the output from print_r, that should help narrow down the problem.
Difficult to debug, but as Terry has said, while debugging, make liberal use of print-r($var) and var_dump($var) so you can visualise your data.

Couple of things I can see. You call the customize function with 2 arguments - $item and $id. Nowhere do you set $id, so I'm assuming it should be $item['id']

$custom->customizing($item, $item['id');

You also echo out esc_html( $item_title ) - should that not be $item['title']

In the customColorFieldOne method, you are creating 3 radio buttons - the first one is named <?php echo $id; ?>-color-picker, while the other 2 are named color-picker. If you want them to act as a group, they should all be named the same.
Avatar of Robert Granlund

ASKER

@Chris and Terry.  I will do what you have asked, however, in the mean time I will post more of the code and more clearly ask my question. The following piece of code generates a checkout form.  Each item in the cart can be customized.

This is the code:
			<?php foreach ( $cart_items as $key => $item ) : ?>
				<tr class="edd_cart_item" id="edd_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-download-id="<?php echo esc_attr( $item['id'] ); ?>">
					<?php do_action( 'edd_checkout_table_body_first', $item ); ?>
					<td class="edd_cart_item_name">
						<?php
							if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
								echo '<div class="edd_cart_item_image">';
									echo get_the_post_thumbnail( $item['id'], apply_filters( 'edd_checkout_image_size', array( 25,25 ) ) );
								echo '</div>';
							}
							$item_title = get_the_title( $item['id'] );
							$id = get_the_title( $item['id'] );
							$variable_pricing = edd_has_variable_prices( $item['id'] );
							if ( ! empty( $item['options'] ) ) {
								$item_title .= ' - ' . edd_get_cart_item_price_name( $item );
							}
							echo '<span class="edd_checkout_cart_item_title">' . esc_html( $item_title ) . '</span>';
						?>
					</td>
					<td class="edd_cart_item_price"><?php echo edd_cart_item_price( $item['id'], $item['options'] ); ?></td>
					<td class="edd_cart_actions">
						<?php if( edd_item_quanities_enabled() ) : ?>
							<input type="number" min="1" step="1" name="edd-cart-download-<?php echo $key; ?>-quantity" class="edd-input edd-item-quantity" value="<?php echo edd_get_cart_item_quantity( $item['id'], $item['options'] ); ?>"/>
							<input type="hidden" name="edd-cart-downloads[]" value="<?php echo $item['id']; ?>"/>
							<input type="hidden" name="edd-cart-download-<?php echo $key; ?>-options" value="<?php esc_attr_e( serialize( $item['options'] ) ); ?>"/>
						<?php endif; ?>
						<a href="<?php echo esc_url( edd_remove_item_url( $key, $post ) ); ?>"><?php _e( 'Remove', 'edd' ); ?></a>
					</td>
					<td>
						<?php 
							$custom = new customize();
							$custom->customButton($item);
						?>
					</td>			
						
			
						
					<?php do_action( 'edd_checkout_table_body_last', $item ); ?>
				</tr>
				<tr>
		<!--  ADD CUSTOM FEAATURE  -->
					<td colspan="4">
						<?php 
							$custom->customizing($item);
						?>
					</td>
		<!--  END CUSTOM FEAATURE  -->	
				</tr>
		
			<?php endforeach; ?>

Open in new window


This function inserts the customizing code:
<?php
function customizing($item)	{
		?>	
<div id='custom-hidden'>

<div class="change-logo-cont">
	<div style="width:250px;padding: 20px 20px 10px;float:left;height:75px;">
		<div style="height:75px;width:75px;float:left;">
			<img alt="" src="http://www.studiohilldesign.com/logoforhire/wp-content/themes/restored-child/images/fonts/color_wheel.png" align="middle" />
		</div>
		<div style="width:175px;height:75px;float:right;">
			<b>Would you like to change logo colors?</b>
		</div>
	</div>
	<div style="width:50px;padding-top:5px; padding-bottom:5px; padding-right:10px;float:left;">
		<span>
		<label for="selectYesEditColor">Yes</label><input id="selectYesEditColor" type="radio" value="logo_color_yes" name="edit_color_group" onclick="ShowColorEditor();"/>
		
		</span>
	</div>
	<div style="width:50px;padding-top:5px; padding-bottom:5px;float:left;" >
		<span>
		<label for="selectNoEditColor">No</label><input id="selectNoEditColor" type="radio" name="edit_color_group" value="logo_color_no" checked="checked" onclick="HideColorEditor();"/>
		
		</span>
	</div>


</div>
<div class="clear"></div>
<div id="show_color_option">
	
	<div style="width:148px;float:left;">
		<?php 
			echo get_the_post_thumbnail( $item['id'], apply_filters( 'edd_checkout_image_size', array( 150,150 ) ) );
		?>
	</div>
	
<div class="custom-color-picker-cont">
		
	<?php
		$this->customColorFieldOne($id);
	?>

	
	<?php
		$this->customColorFieldTwo();
	?>


	<?php
		$this->customColorFieldThree();
	?>	

	</div>
</div>
</div>
<?php }

Open in new window


Once it is inserted and lets say for example there are three items in the cart, the markup looks like this:
<h2 class="post_title">Checkout</h2>
<div id="edd_checkout_wrap">
	<!--dynamic-cached-content-->
	<form id="edd_checkout_cart_form" method="post">
		<div id="edd_checkout_cart_wrap">
			<table id="edd_checkout_cart" class="ajaxed">
				<thead>
					<tr class="edd_cart_header_row">
						<th class="edd_cart_item_name">Item Name</th>
						<th class="edd_cart_item_price">Item Price</th>
						<th class="edd_cart_actions">Actions</th>
						<th class="">Customize</th>
					</tr>
				</thead>
				<tbody>
					<tr class="edd_cart_item" id="edd_cart_item_0_35" data-download-id="35">
						<td class="edd_cart_item_name">
						<div class="edd_cart_item_image"><img width="25" height="25" src="http://studiohilldesign.com/logoforhire/wp-content/uploads/edd/2013/11/logo_1001-46x46.png" class="attachment-25x25 wp-post-image" alt="logo_1001" />
						</div><span class="edd_checkout_cart_item_title">Logo &#8211; 1002 - Customize</span></td>
						<td class="edd_cart_item_price">&#036;69.99</td>
						<td class="edd_cart_actions"><a href="http://studiohilldesign.com/logoforhire/index.php?page_id=4&#038;cart_item=0&#038;edd_action=remove">Remove</a></td>
						<td> CUSTOMIZE
						<br />
						<input type="radio" name="custom_yes" value="custom yes" />
						Yes&nbsp;
						<input type="radio" name="custom_yes" value="custom no"/>
						No </td>

					</tr>
					<tr>
						<!--  ADD CUSTOM FEAATURE  -->
						<td colspan="4">
						<div id='custom-hidden'>

							<div class="change-logo-cont">
								<div style="width:250px;padding: 20px 20px 10px;float:left;height:75px;">
									<div style="height:75px;width:75px;float:left;">
										<img alt="" src="http://www.studiohilldesign.com/logoforhire/wp-content/themes/restored-child/images/fonts/color_wheel.png" align="middle" />
									</div>
									<div style="width:175px;height:75px;float:right;">
										<b>Would you like to change logo colors?</b>
									</div>
								</div>
								<div style="width:50px;padding-top:5px; padding-bottom:5px; padding-right:10px;float:left;">
									<span> <label for="selectYesEditColor">Yes</label>
										<input id="selectYesEditColor" type="radio" value="logo_color_yes" name="edit_color_group" onclick="ShowColorEditor();"/>
									</span>
								</div>
								<div style="width:50px;padding-top:5px; padding-bottom:5px;float:left;" >
									<span> <label for="selectNoEditColor">No</label>
										<input id="selectNoEditColor" type="radio" name="edit_color_group" value="logo_color_no" checked="checked" onclick="HideColorEditor();"/>
									</span>
								</div>

							</div>
							<div class="clear"></div>
							<div id="show_color_option">

								<div style="width:148px;float:left;">
									<img width="150" height="150" src="http://studiohilldesign.com/logoforhire/wp-content/uploads/edd/2013/11/logo_1001-150x150.png" class="attachment-150x150 wp-post-image" alt="logo_1001" />
								</div>

								<div class="custom-color-picker-cont">

									<div class="custom-color-pick-one">

										<table>
											<tr>
												<td width="150px"><span >pick color 1</span>
												<input type="checkbox" value="custom-color" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-1">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="Logo &#8211; 1002-color-picker" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing one"/>
											::  Done Choosing First Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END FIRST HIDDEN COLOR PICKER  -->

									<div class="custom-color-pick-two">

										<table>
											<tr>
												<td width="150px"><span >pick color 2</span>
												<input type="checkbox" value="custom-color-2" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment-2" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-2">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing two"/>
											::  Done Choosing Second Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END SECOND HIDDEN COLOR PICKER  -->

									<div class="custom-color-pick-three">

										<table>
											<tr>
												<td width="150px"><span >pick color 3</span>
												<input type="checkbox" value="custom-color-3" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment-3" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-3">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing three"/>
											::  Done Choosing Third Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END THIRD HIDDEN COLOR PICKER  -->

								</div>
								<!--  END SHOW COLOR OPTION  -->

							</div>
							<!--  END CUSOM COLOR  -->

						</div><!--  END CUSTOM-HIDDEN  --></td>
						<!--  END CUSTOM FEAATURE  -->
					</tr>

					<tr class="edd_cart_item" id="edd_cart_item_1_34" data-download-id="34">
						<td class="edd_cart_item_name">
						<div class="edd_cart_item_image"><img width="25" height="25" src="http://studiohilldesign.com/logoforhire/wp-content/uploads/edd/2013/11/logo_1001-46x46.png" class="attachment-25x25 wp-post-image" alt="logo_1001" />
						</div><span class="edd_checkout_cart_item_title">Logo &#8211; 1003 - Customize</span></td>
						<td class="edd_cart_item_price">&#036;69.99</td>
						<td class="edd_cart_actions"><a href="http://studiohilldesign.com/logoforhire/index.php?page_id=4&#038;cart_item=1&#038;edd_action=remove">Remove</a></td>
						<td> CUSTOMIZE
						<br />
						<input type="radio" name="custom_yes" value="custom yes" />
						Yes&nbsp;
						<input type="radio" name="custom_yes" value="custom no"/>
						No </td>

					</tr>
					<tr>
						<!--  ADD CUSTOM FEAATURE  -->
						<td colspan="4">
						<div id='custom-hidden'>

							<div class="change-logo-cont">
								<div style="width:250px;padding: 20px 20px 10px;float:left;height:75px;">
									<div style="height:75px;width:75px;float:left;">
										<img alt="" src="http://www.studiohilldesign.com/logoforhire/wp-content/themes/restored-child/images/fonts/color_wheel.png" align="middle" />
									</div>
									<div style="width:175px;height:75px;float:right;">
										<b>Would you like to change logo colors?</b>
									</div>
								</div>
								<div style="width:50px;padding-top:5px; padding-bottom:5px; padding-right:10px;float:left;">
									<span> <label for="selectYesEditColor">Yes</label>
										<input id="selectYesEditColor" type="radio" value="logo_color_yes" name="edit_color_group" onclick="ShowColorEditor();"/>
									</span>
								</div>
								<div style="width:50px;padding-top:5px; padding-bottom:5px;float:left;" >
									<span> <label for="selectNoEditColor">No</label>
										<input id="selectNoEditColor" type="radio" name="edit_color_group" value="logo_color_no" checked="checked" onclick="HideColorEditor();"/>
									</span>
								</div>

							</div>
							<div class="clear"></div>
							<div id="show_color_option">

								<div style="width:148px;float:left;">
									<img width="150" height="150" src="http://studiohilldesign.com/logoforhire/wp-content/uploads/edd/2013/11/logo_1001-150x150.png" class="attachment-150x150 wp-post-image" alt="logo_1001" />
								</div>

								<div class="custom-color-picker-cont">

									<div class="custom-color-pick-one">

										<table>
											<tr>
												<td width="150px"><span >pick color 1</span>
												<input type="checkbox" value="custom-color" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-1">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="Logo &#8211; 1003-color-picker" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing one"/>
											::  Done Choosing First Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END FIRST HIDDEN COLOR PICKER  -->

									<div class="custom-color-pick-two">

										<table>
											<tr>
												<td width="150px"><span >pick color 2</span>
												<input type="checkbox" value="custom-color-2" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment-2" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-2">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing two"/>
											::  Done Choosing Second Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END SECOND HIDDEN COLOR PICKER  -->

									<div class="custom-color-pick-three">

										<table>
											<tr>
												<td width="150px"><span >pick color 3</span>
												<input type="checkbox" value="custom-color-3" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment-3" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-3">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing three"/>
											::  Done Choosing Third Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END THIRD HIDDEN COLOR PICKER  -->

								</div>
								<!--  END SHOW COLOR OPTION  -->

							</div>
							<!--  END CUSOM COLOR  -->

							<!--  END CUSTOM-HIDDEN  -->

						</td>
						<!--  END CUSTOM FEAATURE  -->
					</tr>

					<tr class="edd_cart_item" id="edd_cart_item_2_33" data-download-id="33">
						<td class="edd_cart_item_name">
						<div class="edd_cart_item_image"><img width="25" height="25" src="http://studiohilldesign.com/logoforhire/wp-content/uploads/edd/2013/11/logo_1001-46x46.png" class="attachment-25x25 wp-post-image" alt="logo_1001" />
						</div><span class="edd_checkout_cart_item_title">Logo &#8211; 1004 - Customize</span></td>
						<td class="edd_cart_item_price">&#036;69.99</td>
						<td class="edd_cart_actions"><a href="http://studiohilldesign.com/logoforhire/index.php?page_id=4&#038;cart_item=2&#038;edd_action=remove">Remove</a></td>
						<td> CUSTOMIZE
						<br />
						<input type="radio" name="custom_yes" value="custom yes" />
						Yes&nbsp;
						<input type="radio" name="custom_yes" value="custom no"/>
						No </td>

					</tr>
					<tr>
						<!--  ADD CUSTOM FEAATURE  -->
						<td colspan="4">
						<div id='custom-hidden'>

							<div class="change-logo-cont">
								<div style="width:250px;padding: 20px 20px 10px;float:left;height:75px;">
									<div style="height:75px;width:75px;float:left;">
										<img alt="" src="http://www.studiohilldesign.com/logoforhire/wp-content/themes/restored-child/images/fonts/color_wheel.png" align="middle" />
									</div>
									<div style="width:175px;height:75px;float:right;">
										<b>Would you like to change logo colors?</b>
									</div>
								</div>
								<div style="width:50px;padding-top:5px; padding-bottom:5px; padding-right:10px;float:left;">
									<span> <label for="selectYesEditColor">Yes</label>
										<input id="selectYesEditColor" type="radio" value="logo_color_yes" name="edit_color_group" onclick="ShowColorEditor();"/>
									</span>
								</div>
								<div style="width:50px;padding-top:5px; padding-bottom:5px;float:left;" >
									<span> <label for="selectNoEditColor">No</label>
										<input id="selectNoEditColor" type="radio" name="edit_color_group" value="logo_color_no" checked="checked" onclick="HideColorEditor();"/>
									</span>
								</div>

							</div>
							<div class="clear"></div>
							<div id="show_color_option">

								<div style="width:148px;float:left;">
									<img width="150" height="150" src="http://studiohilldesign.com/logoforhire/wp-content/uploads/edd/2013/11/logo_1001-150x150.png" class="attachment-150x150 wp-post-image" alt="logo_1001" />
								</div>

								<div class="custom-color-picker-cont">

									<div class="custom-color-pick-one">

										<table>
											<tr>
												<td width="150px"><span >pick color 1</span>
												<input type="checkbox" value="custom-color" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-1">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="Logo &#8211; 1004-color-picker" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing one"/>
											::  Done Choosing First Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END FIRST HIDDEN COLOR PICKER  -->

									<div class="custom-color-pick-two">

										<table>
											<tr>
												<td width="150px"><span >pick color 2</span>
												<input type="checkbox" value="custom-color-2" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment-2" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-2">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker-2" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing two"/>
											::  Done Choosing Second Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END SECOND HIDDEN COLOR PICKER  -->

									<div class="custom-color-pick-three">

										<table>
											<tr>
												<td width="150px"><span >pick color 3</span>
												<input type="checkbox" value="custom-color-3" style="height:20px;width:70px;border:solid 1px #C7C7C7;" />
												</td>
												<td width="300"><span>please specify which color to change</span>
												<input type="text" name="color-picker-comment-3" value="" style="height:20px;width:325px;border:solid 1px #C7C7C7;" />
												</td>
											</tr>
										</table>
									</div>

									<!--  START FIRST HIDDEN COLOR PICKER  -->
									<div id="custom-color-3">
										<div id="color_pic_cont">

											<!--  SUN  -->
											<div class="custom-color-sun">
												<span class="custom-color-lrg">110</span>
												<br />
												<span class="custom-color-sml">SUN &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="sun"  />
												</span>
											</div>

											<!--  GOLD  -->
											<div class="custom-color-gold">
												<span class="custom-color-lrg">131</span>
												<br />
												<span class="custom-color-sml">GOLD &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="gold" />
												</span>
											</div>

											<!--  CHOCOLATE  -->
											<div class="custom-color-chocolate">
												<span class="custom-color-lrg">7568</span>
												<br />
												<span class="custom-color-sml">CHOCOLATE &nbsp;&nbsp;
													<input type="radio" name="color-picker-3" class="color-picker" value="chocolate" />
												</span>
											</div>

											<input type="checkbox" value="done choosing three"/>
											::  Done Choosing Third Color
										</div>
									</div>
									<div class="clear"></div>
									<!--  END THIRD HIDDEN COLOR PICKER  -->

								</div>
								<!--  END SHOW COLOR OPTION  -->

							</div>
							<!--  END CUSOM COLOR  -->

						</div><!--  END CUSTOM-HIDDEN  --></td>
						<!--  END CUSTOM FEAATURE  -->
					</tr>

					<!-- Show any cart fees, both positive and negative fees -->
				</tbody>
				<tfoot>

Open in new window


As you can see the function Customize() is repeated three times.  However, the three iterations of the code are not named or associated with item-1, item-2, item-3, so when I go to customize the second item, it has all of the info from the first item.  How do I indicate that the second iteration of the function is associated with item 2.  Then when it goes to insert the info, make the final function know that each color is associated:
function custom_purchase_details($payment_meta, $user_info) {
	$color_picker  = isset( $payment_meta['color_picker'] ) ? $payment_meta['color_picker'] : 'none';
	$color_picker_comment  = isset( $payment_meta['color_picker_comment'] ) ? $payment_meta['color_picker_comment'] : 'none';
	$color_picker_2  = isset( $payment_meta['color_picker_2'] ) ? $payment_meta['color_picker_2'] : 'none';
	$color_picker_comment_2  = isset( $payment_meta['color_picker_comment_2'] ) ? $payment_meta['color_picker_comment_2'] : 'none';
	$color_picker_3  = isset( $payment_meta['color_picker_3'] ) ? $payment_meta['color_picker_3'] : 'none';
	$color_picker_comment_3  = isset( $payment_meta['color_picker_comment_3'] ) ? $payment_meta['color_picker_comment_3'] : 'none';
	
	
	$custom_font  = isset( $payment_meta['custom_font'] ) ? $payment_meta['custom_font'] : 'none';
	
	
	?>
	<?php 
		if(isset($color_picker) || isset($color_picker_2) || isset($color_picker_3)) { ?>
	<li><?php echo __('<b>Color Picker One:</b>', 'pippin_edd') . ' ' . $color_picker; ?></li>
	<li><?php echo __('<b>Color One Comment:</b><br />', 'pippin_edd') . ' ' . $color_picker_comment; ?></li>
	<li><?php echo __('<b>Color Picker Two :</b>', 'pippin_edd') . ' ' . $color_picker_2; ?></li>
	<li><?php echo __('<b>Color Two Comment:</b><br />', 'pippin_edd') . ' ' . $color_picker_comment_2; ?></li>
	<li><?php echo __('<b>Color Picker Three:</b>', 'pippin_edd') . ' ' . $color_picker_3; ?></li>
	<li><?php echo __('<b>Color Three Comment:</b><br />', 'pippin_edd') . ' ' . $color_picker_comment_3; ?></li>
	<li><?php echo __('<b>Custom Font:</b>', 'pippin_edd') . ' ' . $custom_font; ?></li>
	<?php } ?>
	<?php
	mailIt($payment_meta, $user_info);
}
add_action('edd_payment_personal_details_list', 'custom_purchase_details', 10, 2);

Open in new window


I have tried to not include as much of the markup that is not needed.  Does this question make sense?
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial