@@ -822,26 +822,23 @@ function kkd_pff_paystack_form_shortcode($atts)
822822 }
823823 $ useinventory = get_post_meta ($ id , '_useinventory ' , true );
824824 $ inventory = get_post_meta ($ id , '_inventory ' ,true );
825- $ sold = get_post_meta ($ id , '_sold ' ,true );
826825 if ($ inventory == "" ) {
827826 $ inventory = '1 ' ;
828827 }
829- if ($ sold == "" ){
830- $ sold = '0 ' ;
831- }
828+
832829 if ($ useinventory == "" ){
833830 $ useinventory = "no " ;
834831 }
835- $ stock = $ inventory - $ sold ;
836832
837- if ($ useinventory == "yes " && $ stock <= 0 ){
833+ if ($ useinventory == "yes " && $ inventory <= 0 ){
838834 echo "<h1>Out of Stock</h1> " ;
839835 }
840836 else if ((($ user_id != 0 ) && ($ loggedin == 'yes ' )) || $ loggedin == 'no ' ) {
841837 echo '<div id="paystack-form"> ' ;
842838 if ($ hidetitle != 1 ) {
843839 echo "<h1 id='pf-form " .$ id ."'> " .$ obj ->post_title ."</h1> " ;
844840 }
841+
845842 echo '<form version=" ' .KKD_PFF_PAYSTACK_VERSION .'" enctype="multipart/form-data" action=" ' . admin_url ('admin-ajax.php ' ) . '" url=" ' . admin_url () . '" method="post" class="paystack-form j-forms" novalidate>
846843 <div class="j-row"> ' ;
847844 echo '<input type="hidden" name="action" value="kkd_pff_paystack_submit_action"> ' ;
@@ -920,9 +917,9 @@ function kkd_pff_paystack_form_shortcode($atts)
920917 <input type="hidden" id="pf-amount" />
921918 <select class="form-control" id="pf-vamount" name="pf-amount"> ' ;
922919 $ max = $ quantity + 1 ;
923- if ($ max > ($ stock +1 )){
924- $ max = $ stock + 1 ;
925- }
920+ if ($ max > ($ inventory +1 ) && $ useinventory == ' yes ' ){
921+ $ max = $ inventory + 1 ;
922+ }
926923 foreach ($ paymentoptions as $ key => $ paymentoption ) {
927924 list ($ a , $ b ) = explode (': ' , $ paymentoption );
928925 echo '<option value=" ' .$ b .'" data-name=" ' .$ a .'"> ' .$ a .' - ' .$ currency .' ' .number_format ($ b ).'</option> ' ;
@@ -948,8 +945,8 @@ function kkd_pff_paystack_form_shortcode($atts)
948945 <select class="form-control" id="pf-quantity" name="pf-quantity" > ' ;
949946 $ max = $ quantity + 1 ;
950947
951- if ($ max > ($ stock +1 ) && $ useinventory == 'yes ' ){
952- $ max = $ stock + 1 ;
948+ if ($ max > ($ inventory +1 ) && $ useinventory == 'yes ' ){
949+ $ max = $ inventory + 1 ;
953950 }
954951 for ($ i =1 ; $ i < $ max ; $ i ++) {
955952 echo ' <option value=" ' .$ i .'"> ' .$ i .'</option> ' ;
@@ -1010,8 +1007,12 @@ function kkd_pff_paystack_form_shortcode($atts)
10101007 </label>
10111008 </div><br> ' ;
10121009 }
1010+ // if($useinventory == "yes" && $usequantity == "yes"){
1011+ // echo '<small>'.$inventory.' left in stock. </small>';
1012+ // }
10131013 echo '<div class="span12 unit">
1014- <small><span style="color: red;">*</span> are compulsory</small><br />
1014+ <small><span style="color: red;">*</span> are compulsory</small><br />
1015+
10151016 <img src=" '.
plugins_url (
'../images/[email protected] ' ,
__FILE__ ) .
'" alt="cardlogos" class="paystack-cardlogos size-full wp-image-1096" /> 10161017
10171018 <button type="reset" class="secondary-btn">Reset</button> ' ;
@@ -1396,10 +1397,7 @@ function kkd_pff_paystack_submit_action()
13961397 $ transaction_charge = get_post_meta ($ _POST ["pf-id " ], '_merchantamount ' , true );
13971398 $ transaction_charge = $ transaction_charge *100 ;
13981399 //--------------------------------------------------------------------------
1399- $ sold = get_post_meta ($ _POST ["pf-id " ], '_sold ' , true );
1400- if ($ sold == '' ){
1401- $ sold = '0 ' ;
1402- }
1400+
14031401 //--------------------------------------------------------------------------
14041402 $ txncharge = get_post_meta ($ _POST ["pf-id " ], '_txncharge ' , true );
14051403 $ minimum = get_post_meta ($ _POST ["pf-id " ], '_minimum ' , true );
@@ -1410,7 +1408,6 @@ function kkd_pff_paystack_submit_action()
14101408 $ originalamount = $ amount ;
14111409 $ quantity = 1 ;
14121410 $ usequantity = get_post_meta ($ _POST ["pf-id " ], '_usequantity ' , true );
1413-
14141411 if (($ recur == 'no ' ) && ($ formamount != 0 )) {
14151412 $ amount = (int )str_replace (' ' , '' , $ formamount );
14161413 }
@@ -1445,13 +1442,7 @@ function kkd_pff_paystack_submit_action()
14451442 }
14461443 //--------------------------------------
14471444
1448- $ sold = $ sold +$ quantity ;
14491445
1450- if (get_post_meta ($ _POST ["pf-id " ], '_sold ' , false )) { // If the custom field already has a value
1451- update_post_meta ($ _POST ["pf-id " ], '_sold ' , $ sold );
1452- } else { // If the custom field doesn't have a value
1453- add_post_meta ($ _POST ["pf-id " ], '_sold ' , $ sold );
1454- }
14551446
14561447 //--------------------------------------
14571448 if ($ txncharge == 'customer ' ) {
@@ -1759,6 +1750,15 @@ function kkd_pff_paystack_confirm_payment()
17591750 // kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
17601751 } else {
17611752 $ usequantity = get_post_meta ($ payment_array ->post_id , '_usequantity ' , true );
1753+ $ useinventory = get_post_meta ($ payment_array ->post_id , '_useinventory ' , true );
1754+ $ inventory = get_post_meta ($ payment_array ->post_id , '_inventory ' , true );
1755+ if ($ useinventory == 'yes ' && $ usequantity == 'yes ' ){
1756+ $ quantity = $ _POST ["quantity " ];
1757+ $ message = $ quantity ;
1758+ $ result = "success " ;
1759+ $ inventory = $ inventory - $ quantity ;
1760+ update_post_meta ($ payment_array ->post_id , '_inventory ' , $ inventory );
1761+ }
17621762 if ($ usequantity == 'no ' ) {
17631763 $ oamount = (int )str_replace (' ' , '' , $ amount );
17641764 } else {
0 commit comments