treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress + Foxycart

  • OK, here's another question for you guys:

    I'm, basically, trying to combine these two bits of code:
    <?php
    $productSize = get_post_meta($post->ID, \"product-size\", false);
    if(!empty($productSize)) {
    print '<label class=\"label_left\">Size: </label>';
    print '<select name=\"Size\">';
    $productSize = get_post_meta($post->ID, \"product-size\", false);
    foreach($productSize as $individualSize) {
    echo \"<option value=\" . $individualSize . \">\" . $individualSize . \"</option>\";
    }
    print '</select>';
    print '<p>';
    }
    ?>


    and

    <?php
    $allOptions = get_post_meta($post=>ID, 'dropdown-product-option', false);
    if ($allOptions) {
    echo \"<select name='options'>\"</select>;
    foreach ($allOptions as $option) {
    $fullValue = explode(\"|\", $option);
    $optionName = $fullValue[0];
    $optionName = $fullValue[1];
    echo \"<option value='$optionName{p+$optionPrice}'>$optionName</option>\"; }
    echo \"</select>\";
    } else {
    echo \"<p id='price-and-code'>$productCode &nbsp; <span class='price'>$$price</span></p>\";
    }}
    ?>


    The second one may be familiar, since Chris used it (assuming I typed it correctly) in one of his screencasts.

    What I need to do is have the size of the product affect the price of the product. And I would like to do it the same way that Chris did: using a | to delineate the second part of the custom field and the php splitting the custom field at that marker and sending the second half as a option modifier that raises (or lowers) the price.

    My custom fields are labeled according to the first set of code.

    Does any of this make sense to anyone?

    Can anyone help?
  • OK, I've banged my head against the wall a few hundred times and I came up with this:

    <!-- WordPress, custom field: product-size <input select list\" -->
    <?php
    $productSize = get_post_meta($post->ID, \"product-size\", false);
    if(!empty($productSize)) {
    print '<label class=\"label_left\">Size: </label>';
    print '<select name=\"Size\">';
    $productSize = get_post_meta($post->ID, \"product-size\", false);
    if ($productSize) {
    foreach($productSize as $individualSize) {
    $fullValue = explode(\"|\", $individualSize);
    $individualSize = $fullValue[0];
    $optionPrice = $fullValue[1];
    echo \"<option value='$individualSize{p+$optionPrice}'>$individualSize</option>\";
    }}
    print '</select>';
    print '<p>';
    }
    ?>



    It seems to work. Can anyone with more php knowledge than I have (not hard that) verify that it seems correct to them?