@@ -824,23 +824,26 @@ function kkd_pff_paystack_form_shortcode($atts)
824824 }
825825 $ useinventory = get_post_meta ($ id , '_useinventory ' , true );
826826 $ inventory = get_post_meta ($ id , '_inventory ' ,true );
827+ $ sold = get_post_meta ($ id , '_sold ' ,true );
827828 if ($ inventory == "" ) {
828829 $ inventory = '1 ' ;
829830 }
830-
831+ if ($ sold == "" ){
832+ $ sold = '0 ' ;
833+ }
831834 if ($ useinventory == "" ){
832835 $ useinventory = "no " ;
833836 }
837+ $ stock = $ inventory - $ sold ;
834838
835- if ($ useinventory == "yes " && $ inventory <= 0 ){
839+ if ($ useinventory == "yes " && $ stock <= 0 ){
836840 echo "<h1>Out of Stock</h1> " ;
837841 }
838842 else if ((($ user_id != 0 ) && ($ loggedin == 'yes ' )) || $ loggedin == 'no ' ) {
839843 echo '<div id="paystack-form"> ' ;
840844 if ($ hidetitle != 1 ) {
841845 echo "<h1 id='pf-form " .$ id ."'> " .$ obj ->post_title ."</h1> " ;
842846 }
843-
844847 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>
845848 <div class="j-row"> ' ;
846849 echo '<input type="hidden" name="action" value="kkd_pff_paystack_submit_action"> ' ;
@@ -919,9 +922,9 @@ function kkd_pff_paystack_form_shortcode($atts)
919922 <input type="hidden" id="pf-amount" />
920923 <select class="form-control" id="pf-vamount" name="pf-amount"> ' ;
921924 $ max = $ quantity + 1 ;
922- if ($ max > ($ inventory +1 ) && $ useinventory == ' yes ' ){
923- $ max = $ inventory + 1 ;
924- }
925+ if ($ max > ($ stock +1 )){
926+ $ max = $ stock + 1 ;
927+ }
925928 foreach ($ paymentoptions as $ key => $ paymentoption ) {
926929 list ($ a , $ b ) = explode (': ' , $ paymentoption );
927930 echo '<option value=" ' .$ b .'" data-name=" ' .$ a .'"> ' .$ a .' - ' .$ currency .' ' .number_format ($ b ).'</option> ' ;
@@ -1009,12 +1012,8 @@ function kkd_pff_paystack_form_shortcode($atts)
10091012 </label>
10101013 </div><br> ' ;
10111014 }
1012- // if($useinventory == "yes" && $usequantity == "yes"){
1013- // echo '<small>'.$inventory.' left in stock. </small>';
1014- // }
10151015 echo '<div class="span12 unit">
1016- <small><span style="color: red;">*</span> are compulsory</small><br />
1017-
1016+ <small><span style="color: red;">*</span> are compulsory</small><br />
10181017 <img src=" '.
plugins_url (
'../images/[email protected] ' ,
__FILE__ ) .
'" alt="cardlogos" class="paystack-cardlogos size-full wp-image-1096" /> 10191018
10201019 <button type="reset" class="secondary-btn">Reset</button> ' ;
@@ -1399,7 +1398,10 @@ function kkd_pff_paystack_submit_action()
13991398 $ transaction_charge = get_post_meta ($ _POST ["pf-id " ], '_merchantamount ' , true );
14001399 $ transaction_charge = $ transaction_charge *100 ;
14011400 //--------------------------------------------------------------------------
1402-
1401+ $ sold = get_post_meta ($ _POST ["pf-id " ], '_sold ' , true );
1402+ if ($ sold == '' ){
1403+ $ sold = '0 ' ;
1404+ }
14031405 //--------------------------------------------------------------------------
14041406 $ txncharge = get_post_meta ($ _POST ["pf-id " ], '_txncharge ' , true );
14051407 $ minimum = get_post_meta ($ _POST ["pf-id " ], '_minimum ' , true );
@@ -1410,6 +1412,7 @@ function kkd_pff_paystack_submit_action()
14101412 $ originalamount = $ amount ;
14111413 $ quantity = 1 ;
14121414 $ usequantity = get_post_meta ($ _POST ["pf-id " ], '_usequantity ' , true );
1415+
14131416 if (($ recur == 'no ' ) && ($ formamount != 0 )) {
14141417 $ amount = (int )str_replace (' ' , '' , $ formamount );
14151418 }
@@ -1444,7 +1447,13 @@ function kkd_pff_paystack_submit_action()
14441447 }
14451448 //--------------------------------------
14461449
1450+ $ sold = $ sold +$ quantity ;
14471451
1452+ if (get_post_meta ($ _POST ["pf-id " ], '_sold ' , false )) { // If the custom field already has a value
1453+ update_post_meta ($ _POST ["pf-id " ], '_sold ' , $ sold );
1454+ } else { // If the custom field doesn't have a value
1455+ add_post_meta ($ _POST ["pf-id " ], '_sold ' , $ sold );
1456+ }
14481457
14491458 //--------------------------------------
14501459 if ($ txncharge == 'customer ' ) {
@@ -1754,15 +1763,6 @@ function kkd_pff_paystack_confirm_payment()
17541763 // kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
17551764 } else {
17561765 $ usequantity = get_post_meta ($ payment_array ->post_id , '_usequantity ' , true );
1757- $ useinventory = get_post_meta ($ payment_array ->post_id , '_useinventory ' , true );
1758- $ inventory = get_post_meta ($ payment_array ->post_id , '_inventory ' , true );
1759- if ($ useinventory == 'yes ' && $ usequantity == 'yes ' ){
1760- $ quantity = $ _POST ["quantity " ];
1761- $ message = $ quantity ;
1762- $ result = "success " ;
1763- $ inventory = $ inventory - $ quantity ;
1764- update_post_meta ($ payment_array ->post_id , '_inventory ' , $ inventory );
1765- }
17661766 if ($ usequantity == 'no ' ) {
17671767 $ oamount = (int )str_replace (' ' , '' , $ amount );
17681768 } else {
0 commit comments