From 211a47ffbe5c09c458ada4669149a3d1657b1ea9 Mon Sep 17 00:00:00 2001 From: "giacomo.secchi" Date: Fri, 14 Apr 2023 17:56:10 +0200 Subject: [PATCH] Disable WC product zoom and quantity input --- functionality-plugin.php | 2 +- includes/class-mcf-woocommerce.php | 66 ++++++++++++++ mu-plugins/custom_functions.php | 111 ------------------------ mu-plugins/project-custom-functions.php | 66 ++++++++++++++ 4 files changed, 133 insertions(+), 112 deletions(-) delete mode 100644 mu-plugins/custom_functions.php create mode 100644 mu-plugins/project-custom-functions.php diff --git a/functionality-plugin.php b/functionality-plugin.php index d46a3fd..69882a1 100644 --- a/functionality-plugin.php +++ b/functionality-plugin.php @@ -5,7 +5,7 @@ * Description: This is an awesome custom plugin with functionality that I'd like to keep when switching things. * Author: Giacomo Secchi * Author URI: https://giacomosecchi.com - * Version: 0.0.13 + * Version: 0.0.14 */ /* Place custom code below this line. */ diff --git a/includes/class-mcf-woocommerce.php b/includes/class-mcf-woocommerce.php index aadb46f..558bda6 100644 --- a/includes/class-mcf-woocommerce.php +++ b/includes/class-mcf-woocommerce.php @@ -18,6 +18,13 @@ define( 'MCF_WOOCOMMERCE_QUANTITY_AS_SELECT', false ); } +if ( ! defined( 'MCF_WOOCOMMERCE_DISABLE_SINGLE_PRODUCT_QTY' ) ) { + define( 'MCF_WOOCOMMERCE_DISABLE_SINGLE_PRODUCT_QTY', false ); +} + +if ( ! defined( 'MCF_WOOCOMMERCE_DISABLE_PRODUCT_ZOOM' ) ) { + define( 'MCF_WOOCOMMERCE_DISABLE_PRODUCT_ZOOM', false ); +} class MCF_WooCommerce { /** @@ -37,6 +44,14 @@ public function __construct() { } + if ( MCF_WOOCOMMERCE_DISABLE_SINGLE_PRODUCT_QTY ) { + $this->disable_quantity_input(); + } + + if ( MCF_WOOCOMMERCE_DISABLE_PRODUCT_ZOOM ) { + $this->disable_product_zoom(); + } + if ( ! MCF_WOOCOMMERCE_REDIRECT_CHECKOUT ) { return false; } @@ -119,4 +134,55 @@ public function woocommerce_loop_add_to_cart_link( $add_to_cart_html ) { public function remove_add_to_cart_message( $message ){ return ''; } + + + // Disable quantity selector for product and product variation + public function disable_quantity_input() { + add_filter( 'woocommerce_quantity_input_args', function ( $args, $product ) { + $args['max_value'] = 1; + + return $args; + }, 10, 2 ); + + add_filter( 'woocommerce_available_variation', function ( $data, $product, $variation ) { + $data['max_qty'] = 1; + + return $data; + }, 10, 3); + } + + // Disable zoom + public function disable_product_zoom() { + add_action( 'wp', function () { + remove_theme_support( 'wc-product-gallery-zoom' ); + // remove_theme_support( 'wc-product-gallery-lightbox' ); + // remove_theme_support( 'wc-product-gallery-slider' ); + } , 100 ); + + add_filter( 'woocommerce_single_product_image_thumbnail_html', function ( $html ) { + return strip_tags( $html, '
' ); + } ); + } + + public function woocommerce_custom_tabs () { + add_filter( 'woocommerce_product_tabs', function( $tabs ) { + + // Remove additional information tab on Product Page + unset( $tabs['reviews'] ); + unset( $tabs['additional_information'] ); + + + // Insert additional information into description tab on Product Page + $tabs['description']['callback'] = function() { + global $product; + wc_get_template( 'single-product/tabs/description.php' ); + + if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) { + wc_get_template( 'single-product/tabs/additional-information.php' ); + } + }; + + return $tabs; + }, 20 ); + } } diff --git a/mu-plugins/custom_functions.php b/mu-plugins/custom_functions.php deleted file mode 100644 index ec7c82c..0000000 --- a/mu-plugins/custom_functions.php +++ /dev/null @@ -1,111 +0,0 @@ -has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) { - // wc_get_template( 'single-product/tabs/additional-information.php' ); - // } - // }; - - return $tabs; -}, 20 ); - - - - -// Disable quantity selector for product and product variation -add_filter( 'woocommerce_quantity_input_args', function ( $args, $product ) { - $args['max_value'] = 1; - - return $args; -}, 10, 2 ); - -add_filter( 'woocommerce_available_variation', function ( $data, $product, $variation ) { - $data['max_qty'] = 1; - - return $data; -}, 10, 3); - - - - - - - - - - diff --git a/mu-plugins/project-custom-functions.php b/mu-plugins/project-custom-functions.php new file mode 100644 index 0000000..45cc0b7 --- /dev/null +++ b/mu-plugins/project-custom-functions.php @@ -0,0 +1,66 @@ +