Woocommerce Subscriptions on-hold in COD [duplicate]












1
















This question already has an answer here:




  • Change COD default order status to “On Hold” instead of “Processing” in Woocommerce

    1 answer



  • Change default order status for COD payment gateway based on user role in Woocommerce

    1 answer




I'm using Cash on delivery on my store to collect the subscriptions from users
But I have a very serious problem that the subscription are goes active without completing the order
I used this code to stop that but it didn't work



add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
function wc_subs_suspend_on_cod( $order ) {

if ( ! is_object( $order ) ) {
$order = new WC_Order( $order );
}

foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {

$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
$payment_gateways = WC()->payment_gateways->payment_gateways();
$payment_gateway = isset( $payment_gateways[ $order->recurring_payment_method ] ) ? $payment_gateways[ $order->recurring_payment_method ] : '';

if ( $payment_gateway->id == 'cod' && $order->get_status() != 'completed' ) {
WC_Subscriptions_Manager::put_subscription_on_hold( $order->user_id, $subscription_key );
}
}
}









share|improve this question













marked as duplicate by LoicTheAztec woocommerce
Users with the  woocommerce badge can single-handedly close woocommerce questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 13:20


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    1
















    This question already has an answer here:




    • Change COD default order status to “On Hold” instead of “Processing” in Woocommerce

      1 answer



    • Change default order status for COD payment gateway based on user role in Woocommerce

      1 answer




    I'm using Cash on delivery on my store to collect the subscriptions from users
    But I have a very serious problem that the subscription are goes active without completing the order
    I used this code to stop that but it didn't work



    add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
    function wc_subs_suspend_on_cod( $order ) {

    if ( ! is_object( $order ) ) {
    $order = new WC_Order( $order );
    }

    foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {

    $subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
    $payment_gateways = WC()->payment_gateways->payment_gateways();
    $payment_gateway = isset( $payment_gateways[ $order->recurring_payment_method ] ) ? $payment_gateways[ $order->recurring_payment_method ] : '';

    if ( $payment_gateway->id == 'cod' && $order->get_status() != 'completed' ) {
    WC_Subscriptions_Manager::put_subscription_on_hold( $order->user_id, $subscription_key );
    }
    }
    }









    share|improve this question













    marked as duplicate by LoicTheAztec woocommerce
    Users with the  woocommerce badge can single-handedly close woocommerce questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 23 '18 at 13:20


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      1












      1








      1









      This question already has an answer here:




      • Change COD default order status to “On Hold” instead of “Processing” in Woocommerce

        1 answer



      • Change default order status for COD payment gateway based on user role in Woocommerce

        1 answer




      I'm using Cash on delivery on my store to collect the subscriptions from users
      But I have a very serious problem that the subscription are goes active without completing the order
      I used this code to stop that but it didn't work



      add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
      function wc_subs_suspend_on_cod( $order ) {

      if ( ! is_object( $order ) ) {
      $order = new WC_Order( $order );
      }

      foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {

      $subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
      $payment_gateways = WC()->payment_gateways->payment_gateways();
      $payment_gateway = isset( $payment_gateways[ $order->recurring_payment_method ] ) ? $payment_gateways[ $order->recurring_payment_method ] : '';

      if ( $payment_gateway->id == 'cod' && $order->get_status() != 'completed' ) {
      WC_Subscriptions_Manager::put_subscription_on_hold( $order->user_id, $subscription_key );
      }
      }
      }









      share|improve this question















      This question already has an answer here:




      • Change COD default order status to “On Hold” instead of “Processing” in Woocommerce

        1 answer



      • Change default order status for COD payment gateway based on user role in Woocommerce

        1 answer




      I'm using Cash on delivery on my store to collect the subscriptions from users
      But I have a very serious problem that the subscription are goes active without completing the order
      I used this code to stop that but it didn't work



      add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
      function wc_subs_suspend_on_cod( $order ) {

      if ( ! is_object( $order ) ) {
      $order = new WC_Order( $order );
      }

      foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {

      $subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
      $payment_gateways = WC()->payment_gateways->payment_gateways();
      $payment_gateway = isset( $payment_gateways[ $order->recurring_payment_method ] ) ? $payment_gateways[ $order->recurring_payment_method ] : '';

      if ( $payment_gateway->id == 'cod' && $order->get_status() != 'completed' ) {
      WC_Subscriptions_Manager::put_subscription_on_hold( $order->user_id, $subscription_key );
      }
      }
      }




      This question already has an answer here:




      • Change COD default order status to “On Hold” instead of “Processing” in Woocommerce

        1 answer



      • Change default order status for COD payment gateway based on user role in Woocommerce

        1 answer








      woocommerce woocommerce-subscriptions






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 7:00









      Gamal ElwazeeryGamal Elwazeery

      607




      607




      marked as duplicate by LoicTheAztec woocommerce
      Users with the  woocommerce badge can single-handedly close woocommerce questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 13:20


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by LoicTheAztec woocommerce
      Users with the  woocommerce badge can single-handedly close woocommerce questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 13:20


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          1














          I found it
          It was the COD order statues
          fixed it bu change the order to "pending"



          function sv_wc_cod_order_status( $status ) {
          return 'pending';
          }
          add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );





          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I found it
            It was the COD order statues
            fixed it bu change the order to "pending"



            function sv_wc_cod_order_status( $status ) {
            return 'pending';
            }
            add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );





            share|improve this answer




























              1














              I found it
              It was the COD order statues
              fixed it bu change the order to "pending"



              function sv_wc_cod_order_status( $status ) {
              return 'pending';
              }
              add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );





              share|improve this answer


























                1












                1








                1







                I found it
                It was the COD order statues
                fixed it bu change the order to "pending"



                function sv_wc_cod_order_status( $status ) {
                return 'pending';
                }
                add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );





                share|improve this answer













                I found it
                It was the COD order statues
                fixed it bu change the order to "pending"



                function sv_wc_cod_order_status( $status ) {
                return 'pending';
                }
                add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 8:58









                Gamal ElwazeeryGamal Elwazeery

                607




                607

















                    Popular posts from this blog

                    To store a contact into the json file from server.js file using a class in NodeJS

                    Redirect URL with Chrome Remote Debugging Android Devices

                    Dieringhausen