NF_Fields_Shipping

Class NF_Field_Shipping.

Defined (1)

The class is defined in the following location(s).

/includes/Fields/Shipping.php  
  1. class NF_Fields_Shipping extends NF_Abstracts_Input 
  2. protected $_name = 'shipping'; 
  3.  
  4. protected $_section = 'pricing'; 
  5.  
  6. protected $_icon = 'truck'; 
  7.  
  8. protected $_aliases = array(); 
  9.  
  10. protected $_type = 'shipping'; 
  11.  
  12. protected $_templates = 'shipping'; 
  13.  
  14. protected $_test_value = '0.00'; 
  15.  
  16. protected $_settings = array( 'shipping_type', 'shipping_cost', 'shipping_options' ); 
  17.  
  18. protected $_settings_exclude = array( 'input_limit_set', 'disable_input', 'required' ); 
  19.  
  20. public function __construct() 
  21. parent::__construct(); 
  22.  
  23. $this->_nicename = __( 'Shipping', 'ninja-forms' ); 
  24.  
  25. add_filter( 'ninja-forms-field-settings-groups', array( $this, 'add_setting_group' ) ); 
  26.  
  27. add_filter( 'ninja_forms_merge_tag_value_shipping', array( $this, 'merge_tag_value' ), 10, 2 ); 
  28.  
  29. public function add_setting_group( $groups ) 
  30. $groups[ 'advanced_shipping' ] = array( 
  31. 'id' => 'advanced_shipping',  
  32. 'label' => __( 'Advanced Shipping', 'ninja-forms' ),  
  33. ); 
  34.  
  35. return $groups; 
  36.  
  37. public function admin_form_element( $id, $value ) 
  38. $field = Ninja_Forms()->form()->get_field( $id ); 
  39.  
  40. $value = $field->get_setting( 'shipping_cost' ); 
  41.  
  42. switch( $field->get_setting( 'shipping_type' ) ) { 
  43. case 'single': 
  44.  
  45. return "<input class='widefat' name='fields[$id]' value='$value' />"; 
  46.  
  47. case 'select': 
  48.  
  49. $options = '<option>--</option>'; 
  50. foreach( $field->get_setting( 'shipping_options' ) as $option ) { 
  51. $selected = ( $value == $option[ 'value' ] ) ? "selected" : ''; 
  52. $options .= "<option value='{$option[ 'value' ]}' $selected>{$option[ 'label' ]}</option>"; 
  53.  
  54. return "<select class='widefat' name='fields[$id]' id=''>$options</select>"; 
  55.  
  56. default: 
  57. return ""; 
  58.  
  59. public function merge_tag_value( $value, $field ) 
  60. if( isset( $field[ 'shipping_type' ] ) ) { 
  61.  
  62. switch( $field[ 'shipping_type' ] ) { 
  63. case 'single': 
  64. $value = $field[ 'shipping_cost' ]; 
  65. break; 
  66. case 'select': 
  67. $value = $field[ 'shipping_options' ]; 
  68. break; 
  69. $value = preg_replace ('/[^\d, \.]/', '', $value ); 
  70. return $value;