From e688bccbb8fbb6adae4f54e799104f09b5f5957e Mon Sep 17 00:00:00 2001 From: summersab Date: Mon, 17 Dec 2018 18:22:18 -0600 Subject: [PATCH 1/2] 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 8cbd54a26175e2bd4afc0e5693acc85e592a5d52 Mon Sep 17 00:00:00 2001 From: summersab Date: Mon, 7 Jan 2019 12:26:59 -0600 Subject: [PATCH 2/2] 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 CF7 CSS add_action('wp_enqueue_scripts', 'load_foxyshop_scripts'); function load_foxyshop_scripts() { // is_page can take an array that uses Page Title, Page Slug or Page ID such as array( 23, 'about-us', 'Contact' ) if ( is_page( array( '23', 'about-us', 'Contact' ) ) ) { if ( function_exists( 'foxyshop_load_site_scripts' ) ) { foxyshop_load_site_scripts(); } } }``` This helps with PageSpeed and SEO. --- adminfunctions.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/adminfunctions.php b/adminfunctions.php index 9cbf384..422fe8a 100755 --- a/adminfunctions.php +++ b/adminfunctions.php @@ -54,9 +54,16 @@ function foxyshop_load_admin_scripts($hook) { foxyshop_date_picker(); } +//Add filter to allow blocking the CSS on non-product pages +function foxyshop_load_css() { + return apply_filters( 'foxyshop_load_css', true ); +} + //Loading in Public Style function foxyshop_load_site_scripts() { - wp_enqueue_style('foxyshop_css', FOXYSHOP_DIR . '/css/foxyshop.css', array(), FOXYSHOP_VERSION); + if (foxyshop_load_css()) { + wp_enqueue_style('foxyshop_css', FOXYSHOP_DIR . '/css/foxyshop.css', array(), FOXYSHOP_VERSION); + } } //Checking For Includes To Be Removed