Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. class WC_Settings_Tab_Demo {
  2. /**
  3. * Bootstraps the class and hooks required actions & filters.
  4. *
  5. */
  6. public static function init() {
  7. add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
  8. add_action( 'woocommerce_settings_tabs_settings_tab_demo', __CLASS__ . '::settings_tab' );
  9. add_action( 'woocommerce_update_options_settings_tab_demo', __CLASS__ . '::update_settings' );
  10. add_action('woocommerce_process_product_meta', __CLASS__ . '::process_meta');
  11. }
  12.  
  13.  
  14. /**
  15. * Add a new settings tab to the WooCommerce settings tabs array.
  16. *
  17. * @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
  18. * @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
  19. */
  20. public static function add_settings_tab( $settings_tabs ) {
  21. $settings_tabs['settings_tab_demo'] = __( 'Pricing', 'woocommerce-settings-tab-demo' );
  22. return $settings_tabs;
  23. }
  24. /**
  25. * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function.
  26. *
  27. * @uses woocommerce_admin_fields()
  28. * @uses self::get_settings()
  29. */
  30. public static function settings_tab() {
  31. woocommerce_admin_fields( self::get_settings() );
  32. }
  33. /**
  34. * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
  35. *
  36. * @uses woocommerce_update_options()
  37. * @uses self::get_settings()
  38. */
  39. public static function update_settings() {
  40. woocommerce_update_options( self::get_settings() );
  41. }
  42.  
  43.  
  44. /**
  45. * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
  46. *
  47. * @uses woocommerce_update_options()
  48. * @uses self::get_settings()
  49. */
  50. public static function process_meta() {
  51.  
  52. }
  53.  
  54.  
  55. /**
  56. * Get all the settings for this plugin for @see woocommerce_admin_fields() function.
  57. *
  58. * @return array Array of settings for @see woocommerce_admin_fields() function.
  59. */
  60. public static function get_settings() {
  61.  
  62. $settings[] = array( 'name' => __( 'Margin settings', 'text-domain' ), 'type' => 'title', 'desc' => __( 'The following options are to configure our margin on top of prices', 'text-domain' ), 'id' => 'wcslider' );
  63.  
  64. $settings[] = array(
  65. 'name' => __( 'Canvas', 'text-domain' ),
  66. 'desc_tip' => __( 'Margin profit in percents added on top of Canvases!', 'text-domain' ),
  67. 'id' => 'canvas',
  68. 'type' => 'text',
  69. );
  70. // Add second text field option
  71. $settings[] = array(
  72. 'name' => __( 'Framed Posters', 'text-domain' ),
  73. 'desc_tip' => __( 'Margin profit in percents added on top of Framed Posters!', 'text-domain' ),
  74. 'id' => 'framed',
  75. 'type' => 'text',
  76. );
  77.  
  78. // Add second text field option
  79. $settings[] = array(
  80. 'name' => __( 'Posters', 'text-domain' ),
  81. 'desc_tip' => __( 'Margin profit in percents added on top of Posters!', 'text-domain' ),
  82. 'id' => 'posters',
  83. 'type' => 'text',
  84. );
  85.  
  86. $settings[] = array( 'type' => 'sectionend', 'id' => 'posters' );
  87.  
  88.  
  89. return apply_filters( 'wc_settings_tab_demo_settings', $settings );
  90. }
  91. }
  92. WC_Settings_Tab_Demo::init();
  93.  
  94. <?php print get_option( 'canvas', true );?> //23
  95. <?php print get_option( 'posters', true );?> //233
  96. <?php print get_option( 'framed', true );?> //21
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement