Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Docs Home

Packages

  • Deposits-for-WooCommerce
    • Bookings
    • Cart
    • Order
    • Other
    • Payment-Plans
      • Views
    • Products
    • Settings

Classes

  • DFW_Deposits
  • DFW_Deposits_For_Bookings
  • DFW_Deposits_Plan
  • DFW_Deposits_Settings
  • DFW_License
  • DFW_Manage_Cart
  • DFW_Manage_Order_Items
  • DFW_Manage_Orders
  • DFW_Manage_Plans
  • DFW_Manage_Products
  • DFW_Payment_Plans_List
  • DFW_Plans_Admin_Settings
  • DFW_Product_Admin_Settings
  • DFW_Scheduled_Plan_Orders
  • DFW_Update_DB
  • EDD_DEPOSITS_Plugin_Updater

Functions

  • dfw_update_po_file
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 
<?php
/**
 * Product Admin Settings
 * 
 * @author Tyche Softwares
 * @since 1.0 
 * @category Classes
 * @package Deposits-for-WooCommerce/Settings
 */

class DFW_Product_Admin_Settings{

    /**
     * Constructor function
     * 
     * @since 1.0
     */
    public function __construct(){
        add_filter( 'woocommerce_product_data_tabs'  ,  array( &$this, 'dfw_add_deposits_tab' ), 10 );
        add_action( 'woocommerce_product_data_panels',  array( &$this, 'dfw_deposits_tab_content_fields' ) );
        add_action( 'woocommerce_process_product_meta', array( &$this, 'dfw_save_deposits_settings') );
    }

    /**
     * Create a deposit settings tab on product admin page
     * 
     * @param array $tabs WooCommerce Product Settings tabs
     * @return array
     * @since 1.0
     */
    public function dfw_add_deposits_tab( $tabs ){
        $tabs[ 'deposits' ] = array(
            'label'  => _( 'Deposits'),
            'target' => 'deposits_tab_content'
        );
        return $tabs;
    }


    /**
     * Display various deposit options
     */
    public function dfw_deposits_tab_content_fields(){
        include( 'views/deposits-tab-content-html.php' ); 
    }

     
    /**
     * Save the deposit settings in the post meta
     * 
     * @param int $post_id Product ID
     * @since 1.0
     */
    public function dfw_save_deposits_settings( $post_id ){
        $options = array(
            'product_deposits_enabled' => '',
            'product_deposit_type'     => '',
            'product_deposit_amount'   => 'float',
            'product_deposit_text'     => '',
            'product_payment_plans'    => 'int'
        );

        foreach( $options as $meta => $sanitize ){
            $value = ! empty( $_POST[ $meta ] ) ? $_POST[ $meta ] : '';
            switch( $sanitize ) {
                case 'int' :
                    $value = $value ? ( is_array( $value ) ? array_map( 'absint', $value ) : absint( $value ) ) : '';
                    break;
                    
                case 'float' :
                    $value = $value ? ( is_array( $value ) ? array_map( 'floatval', $value ) : floatval( $value ) ) : '';
                    break;
                    
                default :
                    $value = is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : sanitize_text_field( $value );
            }
            update_post_meta( $post_id, $meta , $value );
        }
    }
}

$dfw_product_admin_settings = new DFW_Product_Admin_Settings();
API documentation generated by ApiGen