Advertisement
zumixosan

Dokan Save Wholesale 1

Jan 8th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 KB | None | 0 0
  1. /**
  2. * Save extra product data
  3. *
  4. * @since 2.5.3
  5. *
  6. * @param integer $post_id
  7. *
  8. * @return void
  9. */
  10. public function save_pro_product_data( $post_id ) {
  11. if ( ! $post_id ) {
  12. return;
  13. }
  14.  
  15. $is_virtual = isset( $_POST['_virtual'] ) ? 'yes' : 'no';
  16. $product_type = empty( $_POST['product_type'] ) ? 'simple' : stripslashes( $_POST['product_type'] );
  17. // Save lot discount options
  18. // $is_lot_discount = isset( $_POST['_is_lot_discount'] ) ? $_POST['_is_lot_discount'] : 'no';
  19. $is_lot_discount = 'yes';
  20. if ( $is_lot_discount == 'yes' ) {
  21. $lot_discount_quantity = isset( $_POST['_lot_discount_quantity'] ) ? $_POST['_lot_discount_quantity'] : 0;
  22. $lot_discount_amount = isset( $_POST['_lot_discount_amount'] ) ? $_POST['_lot_discount_amount'] : 0;
  23.  
  24.  
  25. //edited code
  26. $lot_discount_quantity_two = isset( $_POST['_lot_discount_quantity_two'] ) ? $_POST['_lot_discount_quantity_two'] : 0;
  27. $lot_discount_amount_two = isset( $_POST['_lot_discount_amount_two'] ) ? $_POST['_lot_discount_amount_two'] : 0;
  28.  
  29. $lot_discount_quantity_three = isset( $_POST['_lot_discount_quantity_three'] ) ? $_POST['_lot_discount_quantity_three'] : 0;
  30. $lot_discount_amount_three = isset( $_POST['_lot_discount_amount_three'] ) ? $_POST['_lot_discount_amount_three'] : 0;
  31.  
  32. $discount_status = $_POST['_discount_status'];
  33.  
  34. //edited code
  35. if ( $lot_discount_quantity == '0' || $lot_discount_amount == '0' ) {
  36. update_post_meta( $post_id, '_lot_discount_quantity', 0);
  37. update_post_meta( $post_id, '_lot_discount_amount', 0);
  38. update_post_meta( $post_id, '_lot_discount_quantity_two', 0 );
  39. update_post_meta( $post_id, '_lot_discount_amount_two', 0 );
  40. update_post_meta( $post_id, '_lot_discount_quantity_three', 0);
  41. update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
  42. update_post_meta( $post_id, '_is_lot_discount', 'yes' );
  43. } else {
  44. update_post_meta( $post_id, '_lot_discount_quantity', $lot_discount_quantity );
  45. update_post_meta( $post_id, '_lot_discount_amount', $lot_discount_amount);
  46. update_post_meta( $post_id, '_is_lot_discount', 'yes' );
  47. update_post_meta($post_id,'_discount_status',$discount_status);
  48. }
  49. //edited Code
  50.  
  51. if ($lot_discount_quantity_two == '0' || $lot_discount_amount_two == '0') {
  52. update_post_meta( $post_id, '_lot_discount_quantity_two', 0 );
  53. update_post_meta( $post_id, '_lot_discount_amount_two', 0 );
  54. update_post_meta( $post_id, '_lot_discount_quantity_three', 0);
  55. update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
  56.  
  57. } else if($lot_discount_quantity != '0'){
  58. if($lot_discount_quantity < $lot_discount_quantity_two){
  59. update_post_meta( $post_id, '_lot_discount_quantity_two', $lot_discount_quantity_two );
  60. update_post_meta( $post_id, '_lot_discount_amount_two', $lot_discount_amount_two );
  61. }
  62. }
  63.  
  64. if ( $lot_discount_quantity_three == '0' || $lot_discount_amount_three == '0') {
  65. update_post_meta( $post_id, '_lot_discount_quantity_three', 0);
  66. update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
  67. } else if($lot_discount_quantity != '0') {
  68. if($lot_discount_quantity_two != '0'){
  69. if($lot_discount_quantity < $lot_discount_quantity_two && $lot_discount_quantity_two < $lot_discount_quantity_three){
  70. update_post_meta( $post_id, '_lot_discount_quantity_three', $lot_discount_quantity_three );
  71. update_post_meta( $post_id, '_lot_discount_amount_three', $lot_discount_amount_three );
  72. }
  73. }
  74.  
  75. }
  76.  
  77. } else if ( $is_lot_discount == 'no') {
  78. // update_post_meta( $post_id, '_lot_discount_quantity', 0 );
  79. // update_post_meta( $post_id, '_lot_discount_amount', 0 );
  80. // update_post_meta( $post_id, '_lot_discount_quantity_two', 0 );
  81. // update_post_meta( $post_id, '_lot_discount_amount_two', 0 );
  82. // update_post_meta( $post_id, '_lot_discount_quantity_three', 0 );
  83. // update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
  84. // //update_post_meta( $post_id, '_is_lot_discount', 'no' );
  85. update_post_meta( $post_id, '_is_lot_discount', 'yes' );
  86. }
  87. // // Save lot discount options
  88. // $is_lot_discount = isset( $_POST['_is_lot_discount'] ) ? $_POST['_is_lot_discount'] : 'no';
  89. // if ( $is_lot_discount == 'yes' ) {
  90. // $lot_discount_quantity = isset( $_POST['_lot_discount_quantity'] ) ? $_POST['_lot_discount_quantity'] : 0;
  91. // $lot_discount_amount = isset( $_POST['_lot_discount_amount'] ) ? $_POST['_lot_discount_amount'] : 0;
  92. // if ( $lot_discount_quantity == '0' || $lot_discount_amount == '0' ) {
  93. // update_post_meta( $post_id, '_lot_discount_quantity', $lot_discount_quantity );
  94. // update_post_meta( $post_id, '_lot_discount_amount', $lot_discount_amount );
  95. // update_post_meta( $post_id, '_is_lot_discount', 'no' );
  96. // } else {
  97. // update_post_meta( $post_id, '_lot_discount_quantity', $lot_discount_quantity );
  98. // update_post_meta( $post_id, '_lot_discount_amount', $lot_discount_amount );
  99. // update_post_meta( $post_id, '_is_lot_discount', $is_lot_discount );
  100. // }
  101. // } else if ( $is_lot_discount == 'no' ) {
  102. // update_post_meta( $post_id, '_lot_discount_quantity', 0 );
  103. // update_post_meta( $post_id, '_lot_discount_amount', 0 );
  104. // update_post_meta( $post_id, '_is_lot_discount', 'no' );
  105. // }
  106.  
  107. // Dimensions
  108. if ( 'no' == $is_virtual ) {
  109.  
  110. if ( isset( $_POST['_weight'] ) ) {
  111. update_post_meta( $post_id, '_weight', ( '' === $_POST['_weight'] ) ? '' : wc_format_decimal( $_POST['_weight'] ) );
  112. }
  113.  
  114. if ( isset( $_POST['_length'] ) ) {
  115. update_post_meta( $post_id, '_length', ( '' === $_POST['_length'] ) ? '' : wc_format_decimal( $_POST['_length'] ) );
  116. }
  117.  
  118. if ( isset( $_POST['_width'] ) ) {
  119. update_post_meta( $post_id, '_width', ( '' === $_POST['_width'] ) ? '' : wc_format_decimal( $_POST['_width'] ) );
  120. }
  121.  
  122. if ( isset( $_POST['_height'] ) ) {
  123. update_post_meta( $post_id, '_height', ( '' === $_POST['_height'] ) ? '' : wc_format_decimal( $_POST['_height'] ) );
  124. }
  125. } else {
  126. update_post_meta( $post_id, '_weight', '' );
  127. update_post_meta( $post_id, '_length', '' );
  128. update_post_meta( $post_id, '_width', '' );
  129. update_post_meta( $post_id, '_height', '' );
  130. }
  131.  
  132. //Save shipping meta data
  133. update_post_meta( $post_id, '_disable_shipping', stripslashes( isset( $_POST['_disable_shipping'] ) ? $_POST['_disable_shipping'] : 'no' ) );
  134.  
  135. if ( isset( $_POST['_overwrite_shipping'] ) && $_POST['_overwrite_shipping'] == 'yes' ) {
  136. update_post_meta( $post_id, '_overwrite_shipping', stripslashes( $_POST['_overwrite_shipping'] ) );
  137. } else {
  138. update_post_meta( $post_id, '_overwrite_shipping', 'no' );
  139. }
  140.  
  141. update_post_meta( $post_id, '_additional_price', stripslashes( isset( $_POST['_additional_price'] ) ? $_POST['_additional_price'] : '' ) );
  142. update_post_meta( $post_id, '_additional_qty', stripslashes( isset( $_POST['_additional_qty'] ) ? $_POST['_additional_qty'] : '' ) );
  143. update_post_meta( $post_id, '_dps_processing_time', stripslashes( isset( $_POST['_dps_processing_time'] ) ? $_POST['_dps_processing_time'] : '' ) );
  144.  
  145. // Save shipping class
  146. $product_shipping_class = ( isset( $_POST['product_shipping_class'] ) && $_POST['product_shipping_class'] > 0 && 'external' !== $product_type ) ? absint( $_POST['product_shipping_class'] ) : '';
  147. wp_set_object_terms( $post_id, $product_shipping_class, 'product_shipping_class' );
  148.  
  149. // Cross sells and upsells
  150. $upsells = isset( $_POST['upsell_ids'] ) ? array_map( 'intval', $_POST['upsell_ids'] ) : array();
  151. $crosssells = isset( $_POST['crosssell_ids'] ) ? array_map( 'intval', $_POST['crosssell_ids'] ) : array();
  152.  
  153. update_post_meta( $post_id, '_upsell_ids', $upsells );
  154. update_post_meta( $post_id, '_crosssell_ids', $crosssells );
  155.  
  156. // Save variations
  157. if ( 'variable' == $product_type ) {
  158. dokan_save_variations( $post_id );
  159. }
  160.  
  161. if ( 'grouped' == $product_type && version_compare( WC_VERSION, '2.7', '>' ) ) {
  162. $product = wc_get_product( $post_id );
  163. $goroup_product_ids = isset( $_POST['grouped_products'] ) ? array_filter( array_map( 'intval', (array) $_POST['grouped_products'] ) ) : array();
  164. $product->set_props( array( 'children' => $goroup_product_ids ) );
  165. $product->save();
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement