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, '