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
class DFW_Product_Admin_Settings{
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') );
}
public function dfw_add_deposits_tab( $tabs ){
$tabs[ 'deposits' ] = array(
'label' => _( 'Deposits'),
'target' => 'deposits_tab_content'
);
return $tabs;
}
public function dfw_deposits_tab_content_fields(){
include( 'views/deposits-tab-content-html.php' );
}
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();