Jump to content

Trying to output multiple <forms>'s using for each, not working


jakobsandberg

Recommended Posts

//display an external link or form button

  if ($product_link = $meta['mp_product_link']) {



    $button = '<a class="mp_link_buynow" href="' . esc_url($product_link) . '">' . __('Buy Now »', 'mp') . '</a>';



  } else {

    if ($all_out) {

      $button .= '<span class="mp_no_stock">' . __('Out of Stock', 'mp') . '</span>';

    } else {

	$button = '<div class="mp_product_variations" name="variation">';



		//create select list if more than one variation

	  if (is_array($meta["mp_price"]) && count($meta["mp_price"]) > 1 && empty($meta["mp_file"])) {
		  
		  // for each as

			foreach ($meta["mp_price"] as $key => &$value) {

			  $disabled = (in_array($key, $no_inventory)) ? ' disabled="disabled"' : '';

			$variation_select = '<form name="' . $key . '" class="mp_buy_form" method="post" action="' . mp_cart_link(false, true) . '">\n';
			  
			  $variation_select .= '<input type="hidden" name="product_id" value="' . $post_id . '" />';
			  $variation_select .= '<input type="hidden" name="variation" value="' . $key . '">';
			  
			  $variation_select .= '<span>' . esc_html($meta["mp_var_name"][$key]) . ' - ';
			  

				if ($meta["mp_is_sale"] && $meta["mp_sale_price"][$key]) {

	        $variation_select .= $mp->format_currency('', $meta["mp_sale_price"][$key]);

	      } else {

	        $variation_select .= $mp->format_currency('', $value);

	      }$variation_select .= "</span>\n";

	      
		  
		  if ($context == 'list') {

      if ($variation_select) {

        	$variation_select .= '<a class="mp_link_buynow" href="' . get_permalink($post_id) . '">' . __('Choose Option »', 'mp') . '</a>';

      } else if ($settings['list_button_type'] == 'addcart') {

        $variation_select .= '<input type="hidden" name="action" value="mp-update-cart" />';

        $variation_select .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />';

      } else if ($settings['list_button_type'] == 'buynow') {

        $variation_select .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />';

      }

    } else {



      $button .= $variation_select;



      //add quantity field if not downloadable

      if ($settings['show_quantity'] && empty($meta["mp_file"])) {

        $button .= '<span class="mp_quantity"><label>' . __('Quantity:', 'mp') . ' <input class="mp_quantity_field" type="text" size="1" name="quantity" value="1" /></label></span> ';

      }



      if ($settings['product_button_type'] == 'addcart') {

        $button .= '<input type="hidden" name="action" value="mp-update-cart" />';

        $button .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />';

      } else if ($settings['product_button_type'] == 'buynow') {

        $button .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />';

      }

    }   $variation_select .= "</form>\n";


	    } //end for each

      $variation_select .= '</div>';
	  

 		} else {

      $button .= '<input type="hidden" name="variation" value="0" />';

		}



    }

  }

 

Everything inbetween "for each" is being looped, except for the <form>. How can I get it to include <form> and </form> in the loop?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.