-
Notifications
You must be signed in to change notification settings - Fork 0
/
markup-by-attribute-for-woocommerce.php
149 lines (130 loc) · 5.45 KB
/
markup-by-attribute-for-woocommerce.php
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* This file is part of the Markup by Attribute for WooCommerce plugin by Mark Tomlinson
*
* @package markup-by-attribute-for-woocommerce
* @author Mark Tomlinson
* @version 3.12
* @copyright (c) 2020 - 2024 Mark Tomlinson. All Rights Reserved.
* @license GNU General Public License v3.0 https://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* Plugin Name: Markup by Attribute for WooCommerce
* Description: This plugin adds product variation markup by attribute to WooCommerce -- the ability to add a markup (or markdown) to an attribute term and have that change the regular and sale price of the associated product variations.
* Plugin URI: https://wordpress.org/plugins/markup-by-attribute-for-woocommerce/
* Tags: WooCommerce, Attribute, Price, Variation, Markup
* Author: MarkTomlinson
* Contributors: MarkTomlinson
* Donate link: https://www.paypal.me/MT2Dev/20
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: markup-by-attribute
* Domain path: /languages
* Version: 3.12
* Build: 202414.01
* Stable tag: trunk
* Tested up to: 6.5
* Requires at least: 4.6
* PHP tested up to: 8.1.2
* Requires PHP: 5.6
* WC tested up to: 8.7.0
* WC requires at least: 3.0
* MySQL tested up to: 8.0.36
*/
// Exit if accessed directly
if (!defined('ABSPATH')) exit();
// Declare Markup-by-Attribute is compatable with HPOS
add_action('before_woocommerce_init', function()
{
if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
}
}
);
// Run Markup by Attribute within WooCommerce
add_action('woocommerce_init', 'mt2mba_main');
function mt2mba_main() {
// Load translations
load_plugin_textdomain('markup-by-attribute', FALSE, dirname(plugin_basename(__FILE__)) . '/languages');
// Set plugin information
define('MT2MBA_PLUGIN_PREFIX', 'MT2MBA');
define('MT2MBA_VERSION', '3.12');
define('MT2MBA_BUILD', 202414.01);
define('MT2MBA_DB_VERSION', 2.1);
define('MT2MBA_SITE_URL', get_bloginfo('wpurl'));
define('MT2MBA_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('MT2MBA_PLUGIN_URL', plugin_dir_url(__FILE__));
define('MT2MBA_PLUGIN_BASENAME', plugin_basename(__FILE__));
define('MT2MBA_PLUGIN_NAME', __('Markup by Attribute', 'markup-by-attribute'));
define('MT2MBA_PRICE_META', __('Product price', 'markup-by-attribute') . ' ');
define('PRODUCT_MARKUP_DESC_BEG', '<span id="mbainfo">');
define('PRODUCT_MARKUP_DESC_END', '</span>');
define('REWRITE_OPTION_PREFIX', 'mt2mba_rewrite_attrb_name_');
define('ATTRB_MARKUP_DESC_BEG', '(' . __('Markup:', 'markup-by-attribute') . ' ');
define('ATTRB_MARKUP_NAME_BEG', ' (');
define('ATTRB_MARKUP_END', ')');
$admin_messages = array(
// Update with dismissible info and warning messages that get displayed at startup
'info' => array(
// Info message #1
'HPOS_Compatability' => __('<em>Markup-by-Attribute</em> is now compatible with HPOS. If <em>Markup-by-Attribute</em> was keeping you from fully utilizing HPOS, you may now be able to enable it.<ol><li>Go to 'WooCommerce >> Settings >> Advanced >> Features'.</li><li>Look for 'Order data storage' and select 'High-performance order storage' (If this is not an option, a list of other incompatible plugins will appear.)</li><li>Save your changes.</li></ol>', 'markup-by-attribute'),
),
'warning' => array(
// Warning message #1
//'unique_message_identifier' => __('message', 'markup-by-attribute'),
),
);
// Register class autoloader
require_once(MT2MBA_PLUGIN_DIR . '/autoloader.php');
MT2MBA_AUTOLOADER::register();
// Add settings and instruction links to plugin page
add_filter("plugin_action_links_" . MT2MBA_PLUGIN_BASENAME, 'add_links');
// Instantiate utility class. Done here in case upgrade required.
global $mt2mba_utility;
$mt2mba_utility = new MT2MBA_UTILITY_GENERAL;
// Set global constants
$mt2mba_utility->get_mba_globals();
// Pull in correct code depending on whether we are in the shop (frontend) or on the admin page (backend).
if (is_admin()){
// -------------
// Back end code
// -------------
// Instantiate admin notices
$notices = new MT2MBA_UTILITY_NOTICES;
$notices->send_notice_array($admin_messages);
// Instantiate admin pointers
new MT2MBA_UTILITY_POINTERS;
// Instantiate attribute admin
new MT2MBA_BACKEND_TERM;
// Instantiate product admin
new MT2MBA_BACKEND_PRODUCT;
} else {
// --------------
// Front end code
// --------------
// Instantiate options drop-down box
new MT2MBA_FRONTEND_OPTIONS;
}
}
/**
* Add links to plugin page
*
* @param array $links Usually just the 'Deactivate' link
* @return array Settings and instructions links plus any that came in
*
*/
function add_links($links) {
// Add Settings link
$mt2mba_links['settings'] =
'<a id="mt2mba_settings" href="admin.php?page=wc-settings&tab=products§ion=mt2mba">' .
__('Settings', 'markup-by-attribute') .
'</a>';
// Add Instructions link
$mt2mba_links['instructions'] =
'<a id="mt2mba_instructions" href="https://wordpress.org/plugins/markup-by-attribute-for-woocommerce/#installation" target="_blank">' .
__('Instructions', 'markup-by-attribute') .
'</a>';
// Restore deactivation link to end of array
return array_merge($mt2mba_links, $links);
}
?>