]> _ Git - physioassist-wordpress.git/commitdiff
Committing previous changes that were awaiting validation. WIP #3678 @12
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 16 Dec 2020 10:28:47 +0000 (10:28 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 16 Dec 2020 10:28:47 +0000 (10:28 +0000)
wp-content/mu-plugins/physioassist/src/WooCommerce/Setup.php
wp-content/themes/physioassist/resources/assets/config.json
wp-content/themes/physioassist/resources/assets/images/icons/cart-add.svg [new file with mode: 0644]
wp-content/themes/physioassist/resources/assets/images/icons/poubelle.svg [new file with mode: 0644]
wp-content/themes/physioassist/resources/assets/styles/components/woocommerce-mini-cart.styl
wp-content/themes/physioassist/resources/assets/styles/components/woocommerce.styl
wp-content/themes/physioassist/resources/views/woocommerce/archive-product.blade.php
wp-content/themes/physioassist/resources/views/woocommerce/mini-cart-link.blade.php [new file with mode: 0644]
wp-content/themes/physioassist/resources/views/woocommerce/mini-cart.blade.php
wp-content/themes/physioassist/resources/views/woocommerce/single-product.blade.php

index c8464639f4b05353d53ba5d47301c92c7f30cf19..4f9715b3e0bf6642f4f091aadb69aa2e91703059 100644 (file)
@@ -19,6 +19,13 @@ class Setup {
         // Add WooCommerce mini-cart to the main nav (primary_navigation)
         add_filter('wp_nav_menu_items', [$this, 'woocommerce_cart_menu'], 10, 2);
 
+        // Update mini-cart link count on AJAX updates
+        add_filter('woocommerce_add_to_cart_fragments', [$this, 'woocommerce_add_to_cart_fragment']);
+
+        // Remove content wrappers
+        remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
+        remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
+
         // Remove product sorting dropdowns
         // Ref: https://rudrastyh.com/woocommerce/remove-product-sorting-dropdown.html
         remove_action('woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30);
@@ -26,6 +33,15 @@ class Setup {
         // Remove product count
         remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
 
+        // Replace add to cart button with icon
+        //add_filter('woocommerce_loop_add_to_cart_link', [$this, 'add_to_cart_button'], 10, 3);
+
+        // Change number of columns on shop page
+        add_filter('loop_shop_columns', function() { return 3; }, 999);
+
+        // Replace remove cart item "x" with custom icon
+        add_filter('woocommerce_cart_item_remove_link', [$this, 'cart_remove_link'], 10, 2);
+
         // Remove product single page meta (Category)
         remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40);
 
@@ -36,13 +52,22 @@ class Setup {
 
         // Also disable the headings in custom tabs
         add_filter('yikes_woocommerce_custom_repeatable_product_tabs_heading', '__return_false');
+
+        // Add Newsletter subscription checkbox to checkout
+        add_action('woocommerce_review_order_before_submit', [$this, 'newsletter_checkbox']);
+        // Save Newsletter checkbox
+        add_action('woocommerce_checkout_update_order_meta', [$this, 'newsletter_checkbox_process']);
     }
 
     public function woocommerce_cart_menu($menu, $args) {
 
+        // The shop is only available on the French version of the site so we need to check this
+        $isFrench = apply_filters('wpml_current_language', NULL) === 'fr';
+
         // Only continue if woocommerce mini cart is available and we're on the primary_navigation menu
         if (!function_exists('woocommerce_mini_cart')
             //|| WC()->cart->cart_contents_count < 1
+            || !$isFrench
             || $args->theme_location !== 'primary_navigation') {
             return $menu;
         }
@@ -52,4 +77,64 @@ class Setup {
         return $menu;
     }
 
+    public function woocommerce_add_to_cart_fragment($fragments) {
+        // Re-run and populate updated cart link template
+        $fragments['a.menu-cart-link'] = template('woocommerce/mini-cart-link');
+
+        return $fragments;
+    }
+
+    public function add_to_cart_button($html, $product, $args) {
+        if ($product->is_purchasable() && !$product->is_sold_individually() && $product->is_in_stock() && 'variable' != $product->get_type() && 'bundle' != $product->get_type()) {
+
+            return sprintf(
+                '<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
+                esc_url( $product->add_to_cart_url() ),
+                esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
+                //esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
+                'add_to_cart_button ajax_add_to_cart', // WooCommerce CSS is a mess so just add these for the JS to hook
+                isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
+                \BladeSvgSage\svg_image('icons/cart-add')->toHtml()
+            );
+
+            //return '<button>'. \BladeSvgSage\svg_image('icons/cart')->toHtml() .'</button><pre>'. print_r($args, true) .'</pre>';
+        }
+
+        return $html;
+    }
+
+
+    public function cart_remove_link($html, $cart_item_key) {
+
+        // Instead of trying to recreate the full HTML link with all the attributes, it's easier
+        // to replace the part we don't want: the &times; with the SVG icon
+        $icon = \BladeSvgSage\svg_image('icons/poubelle')->toHtml();
+
+        return str_replace('&times;', $icon, $html);
+
+    }
+
+    public function newsletter_checkbox() {
+        woocommerce_form_field('newsletter_subscribe', array(
+            'type' => 'checkbox',
+            'class' => [],
+            'label' => __('Je souhaite recevoir la newsletter et les offres de PhysioAssist'),
+            'required' => false,
+            'default' => 1, // Pre-check the checkbox
+        ), WC()->checkout->get_value('newsletter_subscribe'));
+    }
+
+    public function newsletter_checkbox_process($order_ID) {
+
+        $newsletter = (isset($_POST['newsletter_subscribe']) && $_POST['newsletter_subscribe'] == 1) ? __('Oui') : __('Non');
+
+        update_post_meta($order_ID, 'Newsletter', $newsletter);
+
+        // ToDo: send an e-mail notifying when there is a new subscriber
+        if ($newsletter === __('Oui')) {
+            // ADDRESS: $_POST['billing_email']
+        }
+
+    }
+
 }
index 1a096a71c3a13d386ad5ffded0478c8630a14a80..1d89771562b3f35546feee4c7c07e37743a93c28 100644 (file)
@@ -39,7 +39,7 @@
     ]
   },
   "publicPath": "/wp-content/themes/physioassist",
-  "devUrl": "https://physioassist.test",
+  "devUrl": "https://fr.physioassist.test",
   "proxyUrl": "https://localhost:3000",
   "cacheBusting": "[name]_[hash:8]",
   "watch": [
diff --git a/wp-content/themes/physioassist/resources/assets/images/icons/cart-add.svg b/wp-content/themes/physioassist/resources/assets/images/icons/cart-add.svg
new file mode 100644 (file)
index 0000000..235f5fb
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" ?><svg viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1280 704q0-26-19-45t-45-19h-128v-128q0-26-19-45t-45-19-45 19-19 45v128h-128q-26 0-45 19t-19 45 19 45 45 19h128v128q0 26 19 45t45 19 45-19 19-45v-128h128q26 0 45-19t19-45zm-576 832q0 53-37.5 90.5t-90.5 37.5-90.5-37.5-37.5-90.5 37.5-90.5 90.5-37.5 90.5 37.5 37.5 90.5zm896 0q0 53-37.5 90.5t-90.5 37.5-90.5-37.5-37.5-90.5 37.5-90.5 90.5-37.5 90.5 37.5 37.5 90.5zm128-1088v512q0 24-16 42.5t-41 21.5l-1044 122q1 7 4.5 21.5t6 26.5 2.5 22q0 16-24 64h920q26 0 45 19t19 45-19 45-45 19h-1024q-26 0-45-19t-19-45q0-14 11-39.5t29.5-59.5 20.5-38l-177-823h-204q-26 0-45-19t-19-45 19-45 45-19h256q16 0 28.5 6.5t20 15.5 13 24.5 7.5 26.5 5.5 29.5 4.5 25.5h1201q26 0 45 19t19 45z"/></svg>
diff --git a/wp-content/themes/physioassist/resources/assets/images/icons/poubelle.svg b/wp-content/themes/physioassist/resources/assets/images/icons/poubelle.svg
new file mode 100644 (file)
index 0000000..b949c58
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg version="1.1"
+        xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 140 140"
+        xml:space="preserve">
+       <path d="M114.8,43.8H36c-2.4,0-4.4,2-4.4,4.4v78.8c0,7.2,5.9,13.1,13.1,13.1H106c7.2,0,13.1-5.9,13.1-13.1V48.1
+               C119.2,45.7,117.2,43.8,114.8,43.8z M110.4,126.9c0,2.4-2,4.4-4.4,4.4H44.8c-2.4,0-4.4-2-4.4-4.4V52.5h70V126.9z"/>
+       <path d="M62.3,113.8c2.4,0,4.4-2,4.4-4.4v-35c0-2.4-2-4.4-4.4-4.4s-4.4,2-4.4,4.4v35C57.9,111.8,59.9,113.8,62.3,113.8
+               z"/>
+       <path d="M88.5,113.8c2.4,0,4.4-2,4.4-4.4v-35c0-2.4-2-4.4-4.4-4.4s-4.4,2-4.4,4.4v35C84.2,111.8,86.1,113.8,88.5,113.8
+               z"/>
+       <path d="M129.7,11.7c-0.5-2.4-2.8-3.9-5.2-3.4l-29.9,6.4l-0.9-4.3C92.1,3.3,85.2-1.2,78.1,0.3L52.4,5.7
+               c-7.1,1.5-11.6,8.5-10.1,15.6l0.9,4.2l-30,6.4c-2.4,0.5-3.9,2.8-3.4,5.2c0.4,2.1,2.3,3.5,4.3,3.5c0.3,0,0.6,0,0.9-0.1l34.2-7.3
+               c0,0,0,0,0.1,0l42.8-9.1c0,0,0,0,0,0l34.2-7.3C128.7,16.4,130.2,14,129.7,11.7z M50.8,19.5c-0.5-2.4,1-4.7,3.4-5.2l25.7-5.5
+               c0.3-0.1,0.6-0.1,0.9-0.1c2,0,3.8,1.4,4.3,3.5l0.9,4.3l-34.2,7.3L50.8,19.5z"/>
+</svg>
index 1af3df5562445a006782cfec56f87e57e596ac58..ec84f8e7d08014f0c0fcbdd69da30c040461211c 100644 (file)
     margin-bottom: 0.8em;
     margin-top: 0.9em;
 
+    #mobileMenu &
+      width: 26px
+      margin-left: auto
+      margin-right: auto
+
     // Create a larger hover zone for the cart icon to make
     // it easier to touch and keep over when viewing the dropdown
     &:before
       bottom: @top
       left: @top
 
+  &-count
+    position: absolute
+    top: -0.25em
+    left: -0.65em
+    width: 1.5em
+    color: #fff
+    font-size: 12px
+    line-height: 1.5
+    text-align: center
+    border-radius: 50%
+    overflow: hidden
+    background-color: $colors.blue
 
 .sub-menu-mini-cart
   padding: 0
       left: -0.8em
       top: 0
       color: $colors.red !important
-      width: 1.5rem
+      width: 1em
       height: @width
       line-height: 1
-      font-size: @width
+      font-size: 1.7rem
       text-align: center
 
+      svg
+        fill: currentColor
+        width: 0.7em
+        height: @width
+
       &:hover
         color: #fff !important
         background: $colors.red
index 5158f076118008dd591b9f515b3b43560cdb7e2c..103293770603bb667896ef2257ddbec3a3920d01 100644 (file)
@@ -40,7 +40,8 @@
       box-shadow: 0 0 0 2px $colors.dark-blue
 
   #respond input#submit,
-  a.button, 
+  a.button,
+  a.added_to_cart,
   button.button, 
   input.button
     font-smoothing()
@@ -49,6 +50,7 @@
     color: #fff
     font-size: 14px
     font-weight: 700
+    line-height: 1
     text-align: center
     text-transform: uppercase
     transition: background-color 0.15s
       &:disabled[disabled]:hover
         background-color: #888
 
-  a.added_to_cart
-    padding-top: 0
-    margin: 1em
+  .add_to_cart_button
+    position: relative
     color: $colors.dark-blue
 
     &:hover
       color: $colors.blue
 
-  .single_add_to_cart_button
-    margin-left: 1.5em !important
+    &.loading
+      opacity: 0.7
+      cursor: wait
+      pointer-events: none
+
+    // Tick after successfully adding product
+    &.added:after
+      content: '\e017'
+      font-family: 'WooCommerce'
+      display: inline-block
+      position: absolute
+      top: 0
+      right: -2.4em
+      font-size: 1.2em
+      color: #77a464
+
+    svg
+      fill: currentColor
+      margin-left: 1em
+      width: 35px
+
+    + a.added_to_cart
+      margin-top: 1em
+
+  a.added_to_cart
+    display: block
+    width: max-content
+
+  // Remove from cart link
+  a.remove
+    display: flex
+    align-items: center
+    justify-content: center
+    color: $colors.red !important
+    font-size: 1.7rem
+    width: 1em
+    height: @width
+
+    &:hover
+      background-color: $colors.red !important
+
+    svg
+      fill: currentColor
+      width: 0.7em
+      height: @width
 
   // Product grid
   ul.products
     li.product
+
+      +below(550px)
+        width: 100% !important
+
       .woocommerce-loop-category__title,
       .woocommerce-loop-product__title,
       h3
     p.price, span.price
       margin-bottom: 0.5em
 
+    div.summary
+      width: 64%
+      +below(769px)
+        width: 100%
+
     div.images
+      width: 33%
+      +below(769px)
+        width: 100%
+
       .woocommerce-product-gallery__wrapper
         line-height: 1 // So spacing between inline-block images is correct
 
     .elementor-section.elementor-section-boxed > .elementor-container
       padding: 0
 
+  #tab-additional_information
+    h2
+      display: none
+
   // Cart
   &-cart
     table.cart
 //=============
 
 // Quantity input -/+ buttons
+.qib-container
+  margin-right: 1.5em
+  margin-bottom: 0.75em
+
 .qib-button
   position: relative
   text-align: center
index 054ab259e230026e0f6e98b35a872d09778bdcfb..4728e6bb901df6d782d8cde26d8740429d13d9a2 100644 (file)
@@ -21,7 +21,7 @@ the readme will list any important changes.
   <div class="content-inner vertical-spacing">
 
     @php
-      do_action('get_header', 'shop');
+      //do_action('get_header', 'shop');
       do_action('woocommerce_before_main_content');
     @endphp
 
@@ -63,8 +63,8 @@ the readme will list any important changes.
 
     @php
       do_action('woocommerce_after_main_content');
-      do_action('get_sidebar', 'shop');
-      do_action('get_footer', 'shop');
+      //do_action('get_sidebar', 'shop');
+      //do_action('get_footer', 'shop');
     @endphp
 
   </div>
diff --git a/wp-content/themes/physioassist/resources/views/woocommerce/mini-cart-link.blade.php b/wp-content/themes/physioassist/resources/views/woocommerce/mini-cart-link.blade.php
new file mode 100644 (file)
index 0000000..3ad4e65
--- /dev/null
@@ -0,0 +1,6 @@
+<a class="menu-cart-link" href="{{ wc_get_cart_url() }}">
+  @svg('icons/cart', 'menu-cart-icon')
+  @if (($cart_count = WC()->cart->get_cart_contents_count()) > 0)
+    <span class="menu-cart-count">{{ $cart_count }}</span>
+  @endif
+</a>
index d481b57daff71c4865772fb4ccf43fc1f9a3e8ad..f40fad5bbd29e4f1b4092322caa69c56cf18aa81 100644 (file)
@@ -1,7 +1,5 @@
 <li class="menu-cart menu-item">
-  <a class="menu-cart-link" href="{{ wc_get_cart_url() }}">
-      @svg('icons/cart', 'menu-cart-icon')
-  </a>
+  @include('woocommerce.mini-cart-link')
 
   <ul class="sub-menu sub-menu-mini-cart">
     <li>
index 60145998216e725ccbab11353609abf18dc3840a..19694049a2ee71d20f838b7878a91add5f6139a1 100644 (file)
@@ -22,7 +22,7 @@ the readme will list any important changes.
   <div class="content-inner vertical-spacing">
 
     @php
-      do_action('get_header', 'shop');
+      //do_action('get_header', 'shop');
       do_action('woocommerce_before_main_content');
     @endphp
 
@@ -36,8 +36,8 @@ the readme will list any important changes.
 
     @php
       do_action('woocommerce_after_main_content');
-      do_action('get_sidebar', 'shop');
-      do_action('get_footer', 'shop');
+      //do_action('get_sidebar', 'shop');
+      //do_action('get_footer', 'shop');
     @endphp
 
   </div>