Guest User

Untitled

a guest
Jan 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <?php woocommerce_wp_checkbox( array(
  2. 'id' => '_wc_security_deposits_enable' ,
  3. 'label' => __( 'Collect security deposit' , 'woocommerce-security-deposits' ) ,
  4. 'description' => __( 'Enable this to collect a security deposit for this product' , 'woocommerce-security-deposits' ) ,
  5. 'desc_tip' => true ) );
  6. ?>
  7.  
  8. public function process_product_meta( $post_id ){
  9. $product = wc_get_product( $post_id );
  10.  
  11. $enable_security_deposit = isset( $_POST[ '_wc_security_deposits_enable' ] ) ? 'yes' : 'no';
  12.  
  13. $amount_type = ( isset( $_POST[ '_wc_security_deposits_amount_type' ] ) &&
  14. ( $_POST[ '_wc_security_deposits_amount_type' ] === 'fixed' ||
  15. $_POST[ '_wc_security_deposits_amount_type' ] === 'percent' ) ) ?
  16. $_POST[ '_wc_security_deposits_amount_type' ] : 'fixed';
  17.  
  18. $amount = isset( $_POST[ '_wc_security_deposits_deposit_amount' ] ) &&
  19. is_numeric( $_POST[ '_wc_security_deposits_deposit_amount' ] ) ? floatval( $_POST[ '_wc_security_deposits_deposit_amount' ] ) : 0.0;
  20.  
  21. if( $amount <= 0 ){
  22. $enable_security_deposit = 'no';
  23. $amount = '';
  24. }
  25.  
  26. $multiply_by_persons = isset( $_POST[ '_wc_security_deposits_multiply_per_persons' ] ) ? 'yes' : 'no';
  27. $multiply_by_quantity = isset( $_POST[ '_wc_security_deposits_multiply_by_quantity' ] ) ? 'yes' : 'no';
  28.  
  29. $product->update_meta_data( '_wc_security_deposits_enable' , $enable_security_deposit );
  30. $product->update_meta_data( '_wc_security_deposits_multiply_by_quantity' , $multiply_by_quantity );
  31. $product->update_meta_data( '_wc_security_deposits_amount_type' , $amount_type );
  32. $product->update_meta_data( '_wc_security_deposits_deposit_amount' , $amount );
  33.  
  34. if( $product->is_type( 'booking' ) && $product->has_persons() ){
  35. $product->update_meta_data( '_wc_security_deposits_multiply_per_persons' , $multiply_by_persons );
  36. }
  37. $product->save();
  38.  
  39. }
Add Comment
Please, Sign In to add comment