Woocommerce Free Shipping If Subscribe











up vote
0
down vote

favorite












I am using the WooCommerce Subscriptions extension and trying to create a rule as follows:




  1. If user doesn't subscribe to items in cart == Charge shipping.

  2. If user subscribes to cart == Free shipping.


The code works and applies the shipping discount to the recurring order (£35.00)...However, it does not apply the discount to the initial order (still £38.50):



enter image description here



add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );

function add_recurring_postage_fees(WC_Cart $cart ) {
if ( ! empty( $cart->recurring_cart_key ) ) {
$discount = 3.95;
$cart->add_fee( 'You subscribed! Free shipping applied!', -$discount);
return;
}
}


Can't seem to figure out what I'm missing in order to apply the free shipping for BOTH the initial order AND the recurring subscription?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am using the WooCommerce Subscriptions extension and trying to create a rule as follows:




    1. If user doesn't subscribe to items in cart == Charge shipping.

    2. If user subscribes to cart == Free shipping.


    The code works and applies the shipping discount to the recurring order (£35.00)...However, it does not apply the discount to the initial order (still £38.50):



    enter image description here



    add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );

    function add_recurring_postage_fees(WC_Cart $cart ) {
    if ( ! empty( $cart->recurring_cart_key ) ) {
    $discount = 3.95;
    $cart->add_fee( 'You subscribed! Free shipping applied!', -$discount);
    return;
    }
    }


    Can't seem to figure out what I'm missing in order to apply the free shipping for BOTH the initial order AND the recurring subscription?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am using the WooCommerce Subscriptions extension and trying to create a rule as follows:




      1. If user doesn't subscribe to items in cart == Charge shipping.

      2. If user subscribes to cart == Free shipping.


      The code works and applies the shipping discount to the recurring order (£35.00)...However, it does not apply the discount to the initial order (still £38.50):



      enter image description here



      add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );

      function add_recurring_postage_fees(WC_Cart $cart ) {
      if ( ! empty( $cart->recurring_cart_key ) ) {
      $discount = 3.95;
      $cart->add_fee( 'You subscribed! Free shipping applied!', -$discount);
      return;
      }
      }


      Can't seem to figure out what I'm missing in order to apply the free shipping for BOTH the initial order AND the recurring subscription?










      share|improve this question















      I am using the WooCommerce Subscriptions extension and trying to create a rule as follows:




      1. If user doesn't subscribe to items in cart == Charge shipping.

      2. If user subscribes to cart == Free shipping.


      The code works and applies the shipping discount to the recurring order (£35.00)...However, it does not apply the discount to the initial order (still £38.50):



      enter image description here



      add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees', 10, 1 );

      function add_recurring_postage_fees(WC_Cart $cart ) {
      if ( ! empty( $cart->recurring_cart_key ) ) {
      $discount = 3.95;
      $cart->add_fee( 'You subscribed! Free shipping applied!', -$discount);
      return;
      }
      }


      Can't seem to figure out what I'm missing in order to apply the free shipping for BOTH the initial order AND the recurring subscription?







      php wordpress woocommerce cart woocommerce-subscriptions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      LoicTheAztec

      77.6k125991




      77.6k125991










      asked Apr 15 at 0:16









      Giuls

      259111




      259111





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49837375%2fwoocommerce-free-shipping-if-subscribe%23new-answer', 'question_page');
          }
          );

          Post as a guest





































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49837375%2fwoocommerce-free-shipping-if-subscribe%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          Popular posts from this blog

          Coverage of Google Street View

          Full-time equivalent

          Surfing