From e688bccbb8fbb6adae4f54e799104f09b5f5957e Mon Sep 17 00:00:00 2001 From: summersab Date: Mon, 17 Dec 2018 18:22:18 -0600 Subject: [PATCH 1/4] Update helperfunctions.php Added two new filters to the foxyshop_product_variations function: foxyshop_before_variation_field - allows adding code prior to the variation form field element foxyshop_after_variation_field - allows adding code after the variation form field element Added a $labelPosition option to the foxyshop_product_variations function to allow the variation titles to be displayed as placeholder values in the form field elements --- helperfunctions.php | 55 ++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/helperfunctions.php b/helperfunctions.php index fc35a91..892c40f 100755 --- a/helperfunctions.php +++ b/helperfunctions.php @@ -319,8 +319,8 @@ function foxyshop_start_form() { -//Writes Variations (showQuantity 0 = Not Shown, 1 = Above, 2 = Below) -function foxyshop_product_variations($showQuantity = 0, $showPriceVariations = true, $beforeVariation = "", $afterVariation = '
') { +//Writes Variations (showQuantity 0 = Not Shown, 1 = Above, 2 = Below; labelPosition 0 = Before, 1 = Placeholder) +function foxyshop_product_variations($showQuantity = 0, $showPriceVariations = true, $beforeVariation = "", $afterVariation = '
', $labelPosition = 0) { global $post, $product, $foxyshop_settings, $foxyshop_write_variation_include; $writeUploadInclude = 0; $write = ""; @@ -330,7 +330,7 @@ function foxyshop_product_variations($showQuantity = 0, $showPriceVariations = t if ($product['quantity_hide']) $showQuantity = 0; if ($showQuantity == 1) { $write .= foxyshop_get_shipto(); - $write .= foxyshop_quantity(apply_filters("foxyshop_default_quantity_value", 1), $beforeVariation, $afterVariation); + $write .= foxyshop_quantity(apply_filters("foxyshop_default_quantity_value", 1), $beforeVariation, $afterVariation, "", $labelPosition); } //Loop Through Variations @@ -383,15 +383,22 @@ function foxyshop_product_variations($showQuantity = 0, $showPriceVariations = t $className = "variation-" . sanitize_title_with_dashes($variationName); - $writeBeforeVariation = $beforeVariation ? str_replace("%c", $className, $beforeVariation) . "\n" : ""; - $writeAfterVariation = $afterVariation ? $afterVariation . "\n" : ""; + $writeBeforeVariationEl = $beforeVariation ? str_replace("%c", $className, $beforeVariation) . "\n" : ""; + $writeAfterVariation = $afterVariation ? $afterVariation . "\n" : ""; $writeAfterVariationEl = $afterVariation ? $afterVariation . "\n" : ""; + $writeBeforeVariation = apply_filters('foxyshop_before_variation_field', $writeBeforeVariationEl, $variationName); + $writeAfterVariation = apply_filters('foxyshop_after_variation_field', $writeAfterVariationEl, $variationName); if ($variationRequired) $className .= ' foxyshop_required'; //Text if ($variationType == "text") { $write .= $writeBeforeVariation; - $write .= ''."\n"; - $write .= '' . esc_attr(str_replace('_',' ',$variationDisplayName)) . ''."\n"; + $write .= ' 0) $write .= ' style="width: ' . (int)$arrVariationText[0] * 6.5 . 'px;"'; if ($variationDisplayKey) $write .= ' dkey="' . $variationDisplayKey . '"'; if ($arrVariationText[1]) $write .= ' maxlength="' . $arrVariationText[1] . '"'; @@ -401,8 +408,13 @@ function foxyshop_product_variations($showQuantity = 0, $showPriceVariations = t //Textarea } elseif ($variationType == "textarea") { $write .= $writeBeforeVariation; - $write .= ''."\n"; - $write .= ''."\n"; + if ($labelPosition == 0) { + $write .= ''."\n"; + $write .= ''."\n"; + } + else if ($labelPosition == 1) { + $write .= ''."\n"; + } $write .= $writeAfterVariation; //Upload @@ -430,8 +442,14 @@ function foxyshop_product_variations($showQuantity = 0, $showPriceVariations = t //Select if ($variationType == "dropdown") { $write .= $writeBeforeVariation; - $write .= ''."\n"; - $write .= ''."\n"; + } + else if ($labelPosition == 1) { + $write .= '\n"; $write .= $writeAfterVariation; @@ -457,7 +475,7 @@ function foxyshop_product_variations($showQuantity = 0, $showPriceVariations = t //Show Quantity After Variations if ($showQuantity != 1) { $write .= foxyshop_get_shipto(); - if ($showQuantity == 2) $write .= foxyshop_quantity(apply_filters("foxyshop_default_quantity_value", 1), $beforeVariation, $afterVariation); + if ($showQuantity == 2) $write .= foxyshop_quantity(apply_filters("foxyshop_default_quantity_value", 1), $beforeVariation, $afterVariation, "", $labelPosition); } if ($write && !isset($foxyshop_write_variation_include)) { @@ -626,7 +644,7 @@ function foxyshop_insert_multship_js() { //Writes the Quantity Box -function foxyshop_quantity($qty = 1, $beforeVariation = "", $afterVariation = '
', $numberPrefix = "") { +function foxyshop_quantity($qty = 1, $beforeVariation = "", $afterVariation = '
', $numberPrefix = "", $labelPosition = 0) { global $product; if ($beforeVariation) $writeBeforeVariation = str_replace("%c", "foxyshop-quantity-holder", $beforeVariation) . "\n"; @@ -637,13 +655,18 @@ function foxyshop_quantity($qty = 1, $beforeVariation = "", $afterVariation = '< $write = ""; if (isset($writeBeforeVariation)) $write .= $writeBeforeVariation; if ($product['quantity_min'] > 0) $qty = $product['quantity_min']; - $write .= ''."\n"; + if ($labelPosition == 0) { + $write .= ''."\n"; + } if ($product['quantity_max_original'] > 0) { if ($numberPrefix) { $write .= ''; } + if ($labelPosition == 1) { + $write .= '' . "\n"; + } for ($i=($product['quantity_min'] > 0 ? $product['quantity_min'] : 1); $i <= $product['quantity_max_original']; $i++) { $write .= ''."\n"; } @@ -1418,7 +1441,7 @@ function foxyshop_addon_order($orderby) { //Add-On Products -function foxyshop_addon_products($show_qty = false, $before_entry = "", $after_entry = '
') { +function foxyshop_addon_products($show_qty = false, $before_entry = "", $after_entry = '
', $labelPosition = 0) { global $foxyshop_settings, $product, $foxyshop_skip_url_link; if (!$foxyshop_settings['enable_addon_products'] || !$product['addon_products']) return; $original_product = $product; @@ -1460,7 +1483,7 @@ function foxyshop_addon_products($show_qty = false, $before_entry = "", $after_e echo ''; echo ''; foxyshop_price(0, 1); - if ($show_qty) echo foxyshop_quantity(apply_filters("foxyshop_default_quantity_value", 1), "", "", $num); + if ($show_qty) echo foxyshop_quantity(apply_filters("foxyshop_default_quantity_value", 1), "", "", $num, $labelPosition); echo $after_entry; From c2f4d533a8d1bee89d56a73e16a9ae11812db715 Mon Sep 17 00:00:00 2001 From: summersab Date: Mon, 7 Jan 2019 12:47:45 -0600 Subject: [PATCH 2/4] Add filter to block CSS on non-product pages Similar to Contact Form 7, FoxyShop loads its CSS on every page of the website. There may be better ways to handle this, but the way it is handled in CF7 is adding a filter that can be used like so: ``` add_filter( 'foxyshop_load_css', '__return_false' ); // Disable FS CSS add_action('wp_enqueue_scripts', 'load_foxyshop_scripts'); function load_foxyshop_scripts() { //is_page can take an array that uses page title, slug, or ID such as array( 23, 'about-us', 'Contact' ) if ( is_page( array( '235', 'daisies' ) ) ) { if ( function_exists( 'foxyshop_do_load_site_scripts' ) ) { foxyshop_do_load_site_scripts(); } } } ``` This helps with PageSpeed and SEO. --- adminfunctions.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/adminfunctions.php b/adminfunctions.php index 9cbf384..4618489 100755 --- a/adminfunctions.php +++ b/adminfunctions.php @@ -54,9 +54,21 @@ function foxyshop_load_admin_scripts($hook) { foxyshop_date_picker(); } -//Loading in Public Style +//Add filter to allow blocking the CSS on non-product pages +function foxyshop_load_css() { + return apply_filters( 'foxyshop_load_css', true ); +} + +//Check for filter return to proceed with style load function foxyshop_load_site_scripts() { - wp_enqueue_style('foxyshop_css', FOXYSHOP_DIR . '/css/foxyshop.css', array(), FOXYSHOP_VERSION); + if (foxyshop_load_css()) { + foxyshop_do_load_site_scripts(); + } +} + +//Loading in Public Style +function foxyshop_do_load_site_scripts() { + wp_enqueue_style('foxyshop_css', FOXYSHOP_DIR . '/css/foxyshop.css', array(), FOXYSHOP_VERSION); } //Checking For Includes To Be Removed From abeb395b95ba66f72d9c62b0ddfcba868a491c66 Mon Sep 17 00:00:00 2001 From: summersab Date: Mon, 14 Jan 2019 23:55:49 -0600 Subject: [PATCH 3/4] Update variation.process.jquery.js I'm not sure if I can justify this PR without the other changes I've made and added to my site's functions.php. However, this small tweak takes into account the scenario where a user has placeholder text in the quantity select box (it is required that the option be set with the attribute `value="0"`). Prior to this change, the price update would show NaN as a new total price. After this change, the update looks to see if the value is 0. Otherwise, it takes the value of the text. --- js/variation.process.jquery.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/variation.process.jquery.js b/js/variation.process.jquery.js index 65eb204..42278b9 100755 --- a/js/variation.process.jquery.js +++ b/js/variation.process.jquery.js @@ -211,7 +211,11 @@ jQuery(document).ready(function($){ if ($("input.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").length > 0) { totalQty = $("input.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").val(); } else if ($("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").length > 0) { - totalQty = $("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "] option:selected").text(); + if ($("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").val() == 0) { + totalQty = 0; + } else { + totalQty = $("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "] option:selected").text(); + } } else { totalQty = 1; } From 5b58a11721b62b41875b75a43744f98cdcd50dad Mon Sep 17 00:00:00 2001 From: summersab Date: Mon, 14 Jan 2019 23:56:56 -0600 Subject: [PATCH 4/4] Revert "Update variation.process.jquery.js" --- js/variation.process.jquery.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/js/variation.process.jquery.js b/js/variation.process.jquery.js index 42278b9..65eb204 100755 --- a/js/variation.process.jquery.js +++ b/js/variation.process.jquery.js @@ -211,11 +211,7 @@ jQuery(document).ready(function($){ if ($("input.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").length > 0) { totalQty = $("input.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").val(); } else if ($("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").length > 0) { - if ($("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "]").val() == 0) { - totalQty = 0; - } else { - totalQty = $("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "] option:selected").text(); - } + totalQty = $("select.foxyshop_quantity.foxyshop_addon_fields[rel=" + current_id + "] option:selected").text(); } else { totalQty = 1; }