• elbego

    (@elbego)


    Hi all – having bit of trouble adding an option to reduce stock on a product within a deposit login (woo commerce deposits). Currently the options as standard are: ‘deposit’ or ‘full payment’ – I wish to also add ‘both deposit or full payment’ so stock would be reduced if either deposit or full payment is taken.

    Help, much appreciated!

    Updated function#1:

    public function payment_complete_reduce_order_stock($reduce, $order_id) {
        $order = wc_get_order($order_id);
        $status = $order->get_status();
        $reduce_on = get_option('wc_deposits_reduce_stock', 'full');
    
        if ($status === 'partially-paid' && $reduce_on === 'full') {
          $reduce = false;
        }
        else if ($status !== 'partially-paid' && $reduce_on === 'deposit') {
          $reduce = false;
        } //added in...
       else if ($status !== 'partially-paid' && $reduce_on === 'both' || $status == 'partially-paid' && $reduce_on === 'both'){
          $reduce = false;
        }

    Updated function#2:

    'deposits_stock' => array(
              'name'  => __('Reduce Stocks On', 'woocommerce-deposits'),
              'type'  => 'radio',
              'desc'  => __('Choose when to reduce stocks.', 'woocommerce-deposits'),
              'id'    => 'wc_deposits_reduce_stock',
              'options' => array(
                'deposit' => __('Deposit Payment', 'woocommerce-deposits'),
                'full'    => __('Full Payment', 'woocommerce-deposits'),
                // added in...
    	    'both'    => __('Both Full Payment or Deposit', 'woocommerce-deposits')
              ),
              'default' => 'full'
            ),

    This is where I think I fall down:

    Original ‘Save all settings’ function:

    $reduce_stock = isset($_POST['wc_deposits_reduce_stock']) ?
          ($_POST['wc_deposits_reduce_stock'] === 'deposit' ? 'deposit' : 'full') : 'full';

    I’m not sure how to add in the additional option, this doesn’t work!:

    $reduce_stock = isset($_POST['wc_deposits_reduce_stock']) ?
          ($_POST['wc_deposits_reduce_stock'] === 'deposit' ? 'deposit' : 'full' ? 'both' : 'full' ) : 'full';
Viewing 1 replies (of 1 total)
  • Thread Starter elbego

    (@elbego)

    Just to say – I’ve got this working – it’s just the selection in the admin options page that is acting strangely – It defaults to my new option – (which is great for me!), but would be good to know how to get it working properly for if/when it’s needed.

    Cheers

Viewing 1 replies (of 1 total)
  • The topic ‘Adding to a plugin's options’ is closed to new replies.