function print_wp_cart_button_for_product($name, $price, $shipping = 0, $var1 = '', $var2 = '', $var3 = '', $atts = array()) { $addcart = get_option('addToCartButtonName'); if (!$addcart || $addcart == '') { $addcart = __("Add to Cart", "wordpress-simple-paypal-shopping-cart"); } $var_output = ""; if (!empty($var1)) { $var1_pieces = explode('|', $var1); $variation1_name = $var1_pieces[0]; $var_output .= '<span class="wp_cart_variation_name">' . $variation1_name . ' : </span>'; $var_output .= '<select name="variation1" onchange="ReadForm (this.form, false);">'; for ($i = 1; $i < sizeof($var1_pieces); $i++) { $var_output .= '<option value="' . $var1_pieces[$i] . '">' . $var1_pieces[$i] . '</option>'; } $var_output .= '</select><br />'; } if (!empty($var2)) { $var2_pieces = explode('|', $var2); $variation2_name = $var2_pieces[0]; $var_output .= '<span class="wp_cart_variation_name">' . $variation2_name . ' : </span>'; $var_output .= '<select name="variation2" onchange="ReadForm (this.form, false);">'; for ($i = 1; $i < sizeof($var2_pieces); $i++) { $var_output .= '<option value="' . $var2_pieces[$i] . '">' . $var2_pieces[$i] . '</option>'; } $var_output .= '</select><br />'; } if (!empty($var3)) { $var3_pieces = explode('|', $var3); $variation3_name = $var3_pieces[0]; $var_output .= '<span class="wp_cart_variation_name">' . $variation3_name . ' : </span>'; $var_output .= '<select name="variation3" onchange="ReadForm (this.form, false);">'; for ($i = 1; $i < sizeof($var3_pieces); $i++) { $var_output .= '<option value="' . $var3_pieces[$i] . '">' . $var3_pieces[$i] . '</option>'; } $var_output .= '</select><br />'; } $replacement = '<div class="wp_cart_button_wrapper">'; $replacement .= '<form method="post" class="wp-cart-button-form" action="" style="display:inline" onsubmit="return ReadForm(this, true);" ' . apply_filters("wspsc_add_cart_button_form_attr", "") . '>'; if (!empty($var_output)) { //Show variation $replacement .= '<div class="wp_cart_variation_section">' . $var_output . '</div>'; } if (isset($atts['button_image']) && !empty($atts['button_image'])) { //Use the custom button image for this shortcode $replacement .= '<input type="image" src="' . $atts['button_image'] . '" class="wp_cart_button" alt="' . __("Add to Cart", "wordpress-simple-paypal-shopping-cart") . '"/>'; } else { //Use the button text or image value from the settings if (preg_match("/http:/", $addcart) || preg_match("/https:/", $addcart)) { // Use the image as the 'add to cart' button $replacement .= '<input type="image" src="' . $addcart . '" class="wp_cart_button" alt="' . __("Add to Cart", "wordpress-simple-paypal-shopping-cart") . '"/>'; } else { $replacement .= '<input type="submit" value="' . apply_filters('wspsc_add_cart_submit_button_value', $addcart, $price) . '" />'; } } $replacement .= '<input type="hidden" name="wspsc_product" value="' . $name . '" /><input type="hidden" name="price" value="' . $price . '" /><input type="hidden" name="shipping" value="' . $shipping . '" /><input type="hidden" name="addcart" value="1" /><input type="hidden" name="cartLink" value="' . cart_current_page_url() . '" />'; $replacement .= '<input type="hidden" name="product_tmp" value="' . $name . '" />'; isset($atts['item_number']) ? $item_num = $atts['item_number'] : ($item_num = ''); $replacement .= '<input type="hidden" name="item_number" value="' . $item_num . '" />'; if (isset($atts['file_url'])) { $file_url = $atts['file_url']; $file_url = base64_encode($file_url); $replacement .= '<input type="hidden" name="file_url" value="' . $file_url . '" />'; } if (isset($atts['thumbnail'])) { $replacement .= '<input type="hidden" name="thumbnail" value="' . $atts['thumbnail'] . '" />'; } if (isset($atts['stamp_pdf'])) { $replacement .= '<input type="hidden" name="stamp_pdf" value="' . $atts['stamp_pdf'] . '" />'; } $p_key = get_option('wspsc_private_key_one'); if (empty($p_key)) { $p_key = uniqid(); update_option('wspsc_private_key_one', $p_key); } $hash_one = md5($p_key . '|' . $price); $replacement .= '<input type="hidden" name="hash_one" value="' . $hash_one . '" />'; $replacement .= '</form>'; $replacement .= '</div>'; return $replacement; }
function print_wp_cart_button_for_product($name, $price, $shipping = 0) { $addcart = get_option('addToCartButtonName'); if (!$addcart || $addcart == '') { $addcart = __("Add to Cart", "WSPSC"); } $replacement = '<div class="wp_cart_button_wrapper">'; $replacement .= '<form method="post" class="wp-cart-button-form" action="" style="display:inline">'; if (preg_match("/http:/", $addcart)) { $replacement .= '<input type="image" src="' . $addcart . '" class="wp_cart_button" alt="' . __("Add to Cart", "WSPSC") . '"/>'; } else { $replacement .= '<input type="submit" value="' . $addcart . '" />'; } $replacement .= '<input type="hidden" name="product" value="' . $name . '" /><input type="hidden" name="price" value="' . $price . '" /><input type="hidden" name="shipping" value="' . $shipping . '" /><input type="hidden" name="addcart" value="1" /><input type="hidden" name="cartLink" value="' . cart_current_page_url() . '" />'; $replacement .= '</form>'; $replacement .= '</div>'; return $replacement; }