You've already forked wc-tier-and-package-prices
Release version 1.0.2
- Migrate settings to WooCommerce Settings page - Add WC_TPP_Settings class for proper WooCommerce integration - Remove standalone settings submenu - Improve UX with native WooCommerce settings UI
This commit is contained in:
@@ -10,39 +10,24 @@ if (!defined('ABSPATH')) {
|
||||
class WC_TPP_Admin {
|
||||
|
||||
public function __construct() {
|
||||
add_action('admin_menu', array($this, 'add_admin_menu'));
|
||||
add_action('admin_init', array($this, 'register_settings'));
|
||||
add_filter('woocommerce_get_settings_pages', array($this, 'add_settings_page'));
|
||||
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
|
||||
}
|
||||
|
||||
public function add_admin_menu() {
|
||||
add_submenu_page(
|
||||
'woocommerce',
|
||||
__('Tier & Package Prices', 'wc-tier-package-prices'),
|
||||
__('Tier & Package Prices', 'wc-tier-package-prices'),
|
||||
'manage_woocommerce',
|
||||
'wc-tier-package-prices',
|
||||
array($this, 'settings_page')
|
||||
);
|
||||
}
|
||||
|
||||
public function register_settings() {
|
||||
register_setting('wc_tpp_settings', 'wc_tpp_enable_tier_pricing');
|
||||
register_setting('wc_tpp_settings', 'wc_tpp_enable_package_pricing');
|
||||
register_setting('wc_tpp_settings', 'wc_tpp_display_table');
|
||||
register_setting('wc_tpp_settings', 'wc_tpp_display_position');
|
||||
/**
|
||||
* Add settings page to WooCommerce settings
|
||||
*/
|
||||
public function add_settings_page($settings) {
|
||||
$settings[] = include WC_TPP_PLUGIN_DIR . 'includes/class-wc-tpp-settings.php';
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function enqueue_admin_scripts($hook) {
|
||||
if ('woocommerce_page_wc-tier-package-prices' === $hook || 'post.php' === $hook || 'post-new.php' === $hook) {
|
||||
if ('woocommerce_page_wc-settings' === $hook || 'post.php' === $hook || 'post-new.php' === $hook) {
|
||||
wp_enqueue_style('wc-tpp-admin', WC_TPP_PLUGIN_URL . 'assets/css/admin.css', array(), WC_TPP_VERSION);
|
||||
wp_enqueue_script('wc-tpp-admin', WC_TPP_PLUGIN_URL . 'assets/js/admin.js', array('jquery'), WC_TPP_VERSION, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function settings_page() {
|
||||
WC_TPP_Template_Loader::get_instance()->display('admin/settings-page.twig');
|
||||
}
|
||||
}
|
||||
|
||||
new WC_TPP_Admin();
|
||||
|
||||
134
includes/class-wc-tpp-settings.php
Normal file
134
includes/class-wc-tpp-settings.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Settings Integration
|
||||
*
|
||||
* Adds Tier & Package Prices settings to WooCommerce Settings > Advanced tab
|
||||
*
|
||||
* @package WC_Tier_Package_Prices
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!class_exists('WC_Settings_Page')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* WC_TPP_Settings class
|
||||
*/
|
||||
class WC_TPP_Settings extends WC_Settings_Page {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'tier_package_prices';
|
||||
$this->label = __('Tier & Package Prices', 'wc-tier-package-prices');
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
'' => __('General', 'wc-tier-package-prices'),
|
||||
);
|
||||
|
||||
return apply_filters('woocommerce_get_sections_' . $this->id, $sections);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array
|
||||
*
|
||||
* @param string $current_section Current section name.
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings($current_section = '') {
|
||||
$settings = array();
|
||||
|
||||
if ('' === $current_section) {
|
||||
$settings = array(
|
||||
array(
|
||||
'title' => __('Tier & Package Prices Settings', 'wc-tier-package-prices'),
|
||||
'type' => 'title',
|
||||
'desc' => __('Configure tier pricing and package pricing options for your WooCommerce products.', 'wc-tier-package-prices'),
|
||||
'id' => 'wc_tpp_settings',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __('Enable Tier Pricing', 'wc-tier-package-prices'),
|
||||
'desc' => __('Enable tier pricing for products', 'wc-tier-package-prices'),
|
||||
'id' => 'wc_tpp_enable_tier_pricing',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => __('Allow quantity-based pricing tiers. Customers get discounted prices when buying in larger quantities.', 'wc-tier-package-prices'),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __('Enable Package Pricing', 'wc-tier-package-prices'),
|
||||
'desc' => __('Enable fixed-price packages for products', 'wc-tier-package-prices'),
|
||||
'id' => 'wc_tpp_enable_package_pricing',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => __('Allow fixed-price packages with specific quantities. For example: 10 pieces for $50, 25 pieces for $100.', 'wc-tier-package-prices'),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __('Display Pricing Table', 'wc-tier-package-prices'),
|
||||
'desc' => __('Show tier and package pricing table on product pages', 'wc-tier-package-prices'),
|
||||
'id' => 'wc_tpp_display_table',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => __('Display the pricing table to customers on product pages.', 'wc-tier-package-prices'),
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __('Display Position', 'wc-tier-package-prices'),
|
||||
'desc' => __('Choose where to display the pricing table on product pages.', 'wc-tier-package-prices'),
|
||||
'id' => 'wc_tpp_display_position',
|
||||
'default' => 'after_add_to_cart',
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => true,
|
||||
'options' => array(
|
||||
'before_add_to_cart' => __('Before Add to Cart Button', 'wc-tier-package-prices'),
|
||||
'after_add_to_cart' => __('After Add to Cart Button', 'wc-tier-package-prices'),
|
||||
'after_price' => __('After Price', 'wc-tier-package-prices'),
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'wc_tpp_settings',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return apply_filters('woocommerce_get_settings_' . $this->id, $settings, $current_section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings
|
||||
*/
|
||||
public function output() {
|
||||
$settings = $this->get_settings();
|
||||
WC_Admin_Settings::output_fields($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*/
|
||||
public function save() {
|
||||
$settings = $this->get_settings();
|
||||
WC_Admin_Settings::save_fields($settings);
|
||||
}
|
||||
}
|
||||
|
||||
return new WC_TPP_Settings();
|
||||
Reference in New Issue
Block a user