-
-
Save JustinSainton/9077016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* This actually all looks fine and shouldn't be problematic really. I'd do a few things differently, most likely, but mostly because I'd envision it within the WordPress context. */ | |
function get_list_view_html( $product_id, $product ) { | |
$products = get_products_all(); | |
$output = ""; | |
$output = $output . "<li>"; | |
$output = $output . '<a href="shirt.php?id=' . $product_id . '">'; | |
$output = $output . '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">'; | |
$output = $output . "<p>View Details</p>"; | |
$output = $output . "</a>" | |
$output = $output . "</li>"; | |
return $output; | |
} | |
// This is what I did to add the dropdown and submit button. some lines are commented out as I was messing around. | |
function get_list_view_html($product_id, $product){ | |
$products = get_products_all(); | |
$output = ""; | |
$output = $output . "<li>"; | |
$output = $output . '<a href="shirt.php?id=' . $product_id . '">'; | |
$output = $output . '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">'; | |
$output = $output . "<p>View Details</p>"; | |
$output = $output . "</a>"; | |
/* All good so far */ | |
/* Worth noting that, rather than "$output = $output . whatever", you can actually just do $output .= $whatever */ | |
/* The ".=" is the same as $output = $output . $whatever. */ | |
$output = $output . '<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">'; | |
$output = $output . '<input type="hidden" name="cmd" value="_s-xclick">'; | |
$output = $output . '<input type="hidden" name="hosted_button_id" value="<?php echo $product["paypal"]; ?>">'; | |
$output = $output . '<input type="hidden" name="item_name" value="<?php echo $product["name"]; ?>">'; | |
$output = $output . '<input type="hidden" name="on0" value="Size">'; | |
/* Really shouldn't ever be using tables for anything other than tabular data, so I'm removing the commented out tables. */ | |
$output = $output . '<label for="os0">Size</label>'; | |
$output = $output . '<select name="os0" id="os0">'; | |
/* This is where things fall apart. You have PHP expressions within a string ('') */ | |
/* I'll comment out what you had, and paste in what it should be. */ | |
//$output = $output . '<?php foreach($product["sizes"] as $size) { ; | |
//$output = $output . '<option value="<?php echo $size;"><?php echo $size></option>'; | |
//$output = $output . '<?php } '; | |
foreach ( $product["sizes"] as $size ) { | |
$output .= '<option value="' . $size; . '">' . $size . '</option>'; | |
} | |
$output .= '</select>'; | |
$output = $output . '<input type="submit" value="Add to Cart" name="submit" id="small_submit">'; | |
$output = $output . '</form>'; | |
$output = $output . "</li>"; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment