| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Volume Discounts Options. |
| 5 |
* |
| 6 |
* @package Merchant |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
Merchant_Admin_Options::create( array( |
| 14 |
'title' => esc_html__( 'Offers', 'merchant' ), |
| 15 |
'module' => Merchant_Volume_Discounts::MODULE_ID, |
| 16 |
'fields' => array( |
| 17 |
array( |
| 18 |
'id' => 'offers', |
| 19 |
'type' => 'flexible_content', |
| 20 |
'button_label' => esc_html__( 'Add New Offer', 'merchant' ), |
| 21 |
'style' => Merchant_Volume_Discounts::MODULE_ID . '-style default', |
| 22 |
'sorting' => true, |
| 23 |
'accordion' => true, |
| 24 |
'duplicate' => true, |
| 25 |
'layouts' => array( |
| 26 |
'offer-details' => array( |
| 27 |
'title' => esc_html__( 'Create Discount Tiers', 'merchant' ), |
| 28 |
'title-field' => 'offer-title', // text field ID to use as title for the layout |
| 29 |
'fields' => array( |
| 30 |
array( |
| 31 |
'id' => 'offer-title', |
| 32 |
'type' => 'text', |
| 33 |
'title' => esc_html__( 'Offer name', 'merchant' ), |
| 34 |
'default' => esc_html__( 'Campaign', 'merchant' ), |
| 35 |
), |
| 36 |
array( |
| 37 |
'id' => 'rules_to_display', |
| 38 |
'type' => 'select', |
| 39 |
'title' => esc_html__( 'Offered product(s)', 'merchant' ), |
| 40 |
'options' => array( |
| 41 |
'all' => esc_html__( 'All products', 'merchant' ), |
| 42 |
'products' => esc_html__( 'Specific products', 'merchant' ), |
| 43 |
'categories' => esc_html__( 'Specific categories', 'merchant' ), |
| 44 |
'tags' => esc_html__( 'Specific tags', 'merchant' ), |
| 45 |
), |
| 46 |
'default' => 'products', |
| 47 |
), |
| 48 |
array( |
| 49 |
'id' => 'product_id', |
| 50 |
'type' => 'products_selector', |
| 51 |
//'title' => esc_html__( 'Select product', 'merchant' ), |
| 52 |
'multiple' => true, |
| 53 |
'desc' => esc_html__( 'Select the product that the customer will get a discount on when they purchase the minimum required quantity.', |
| 54 |
'merchant' ), |
| 55 |
'allowed_types' => array( 'simple', 'variable' ), |
| 56 |
'condition' => array( 'rules_to_display', '==', 'products' ), |
| 57 |
), |
| 58 |
array( |
| 59 |
'id' => 'category_slugs', |
| 60 |
'type' => 'select_ajax', |
| 61 |
'title' => esc_html__( 'Categories', 'merchant' ), |
| 62 |
'source' => 'options', |
| 63 |
'multiple' => true, |
| 64 |
'options' => Merchant_Admin_Options::get_category_select2_choices(), |
| 65 |
'placeholder' => esc_html__( 'Select categories', 'merchant' ), |
| 66 |
'desc' => esc_html__( 'Select the product categories that will show the offer.', 'merchant' ), |
| 67 |
'condition' => array( 'rules_to_display', '==', 'categories' ), |
| 68 |
), |
| 69 |
array( |
| 70 |
'id' => 'tag_slugs', |
| 71 |
'type' => 'select_ajax', |
| 72 |
'title' => esc_html__( 'Tags', 'merchant' ), |
| 73 |
'source' => 'options', |
| 74 |
'multiple' => true, |
| 75 |
'options' => Merchant_Admin_Options::get_tag_select2_choices(), |
| 76 |
'placeholder' => esc_html__( 'Select tags', 'merchant' ), |
| 77 |
'desc' => esc_html__( 'Select the product tags that will show the offer.', 'merchant' ), |
| 78 |
'condition' => array( 'rules_to_display', '==', 'tags' ), |
| 79 |
), |
| 80 |
array( |
| 81 |
'id' => 'excluded_products', |
| 82 |
'type' => 'products_selector', |
| 83 |
'title' => esc_html__( 'Exclude Products', 'merchant' ), |
| 84 |
'multiple' => true, |
| 85 |
'desc' => esc_html__( 'Exclude products from this campaign.', 'merchant' ), |
| 86 |
'condition' => array( 'rules_to_display', 'any', 'all|categories|tags' ), |
| 87 |
), |
| 88 |
array( |
| 89 |
'id' => 'quantity', |
| 90 |
'type' => 'number', |
| 91 |
'title' => esc_html__( 'Quantity', 'merchant' ), |
| 92 |
'default' => 2, |
| 93 |
), |
| 94 |
|
| 95 |
array( |
| 96 |
'id' => 'discount_type', |
| 97 |
'type' => 'radio', |
| 98 |
'title' => esc_html__( 'Discount', 'merchant' ), |
| 99 |
'options' => array( |
| 100 |
'percentage_discount' => esc_html__( 'Percentage', 'merchant' ), |
| 101 |
'fixed_discount' => esc_html__( 'Fixed', 'merchant' ), |
| 102 |
), |
| 103 |
'default' => 'fixed_discount', |
| 104 |
), |
| 105 |
array( |
| 106 |
'id' => 'discount', |
| 107 |
'type' => 'number', |
| 108 |
'default' => 10, |
| 109 |
), |
| 110 |
|
| 111 |
array( |
| 112 |
'id' => 'exclude_coupon', |
| 113 |
'type' => 'switcher', |
| 114 |
'title' => esc_html__( 'Exclude coupons', 'merchant' ), |
| 115 |
'desc' => esc_html__( 'Coupon codes will not be applicable on top of this offer campaign.', 'merchant' ), |
| 116 |
'default' => false, |
| 117 |
), |
| 118 |
|
| 119 |
array( |
| 120 |
'id' => 'user_condition', |
| 121 |
'type' => 'select', |
| 122 |
'title' => esc_html__( 'User Condition', 'merchant' ), |
| 123 |
'options' => array( |
| 124 |
'all' => esc_html__( 'All Users', 'merchant' ), |
| 125 |
'customers' => esc_html__( 'Selected Users', 'merchant' ), |
| 126 |
'roles' => esc_html__( 'Selected Roles', 'merchant' ), |
| 127 |
), |
| 128 |
'default' => 'all', |
| 129 |
), |
| 130 |
|
| 131 |
array( |
| 132 |
'id' => 'user_condition_roles', |
| 133 |
'type' => 'select_ajax', |
| 134 |
'title' => esc_html__( 'User Roles', 'merchant' ), |
| 135 |
'desc' => esc_html__( 'This will limit the offer to users with these roles.', 'merchant' ), |
| 136 |
'source' => 'options', |
| 137 |
'multiple' => true, |
| 138 |
'classes' => array( 'flex-grow' ), |
| 139 |
'options' => Merchant_Admin_Options::get_user_roles_select2_choices(), |
| 140 |
'condition' => array( 'user_condition', '==', 'roles' ), |
| 141 |
), |
| 142 |
|
| 143 |
array( |
| 144 |
'id' => 'user_condition_users', |
| 145 |
'type' => 'select_ajax', |
| 146 |
'title' => esc_html__( 'Users', 'merchant' ), |
| 147 |
'desc' => esc_html__( 'This will limit the offer to the selected customers.', 'merchant' ), |
| 148 |
'source' => 'user', |
| 149 |
'multiple' => true, |
| 150 |
'classes' => array( 'flex-grow' ), |
| 151 |
'condition' => array( 'user_condition', '==', 'customers' ), |
| 152 |
), |
| 153 |
|
| 154 |
array( |
| 155 |
'id' => 'single_product_placement', |
| 156 |
'type' => 'radio', |
| 157 |
'title' => esc_html__( 'Placement on product page', 'merchant' ), |
| 158 |
'options' => array( |
| 159 |
'before-cart-form' => esc_html__( 'Before add to cart', 'merchant' ), |
| 160 |
'after-cart-form' => esc_html__( 'After add to cart', 'merchant' ), |
| 161 |
), |
| 162 |
'default' => 'before-cart-form', |
| 163 |
), |
| 164 |
|
| 165 |
// text formatting |
| 166 |
array( |
| 167 |
'id' => 'table_title', |
| 168 |
'type' => 'text', |
| 169 |
'title' => esc_html__( 'Offer title', 'merchant' ), |
| 170 |
'default' => __( 'Buy more, save more!', 'merchant' ), |
| 171 |
), |
| 172 |
|
| 173 |
// `hidden_desc` depends on `desc` |
| 174 |
array( |
| 175 |
'id' => 'save_label', |
| 176 |
'type' => 'text', |
| 177 |
'title' => esc_html__( 'Save label', 'merchant' ), |
| 178 |
'default' => esc_html__( 'Save {amount}', 'merchant' ), |
| 179 |
'desc' => __( 'You can use these codes in the content.', 'merchant' ), |
| 180 |
'hidden_desc' => sprintf( |
| 181 |
/* Translators: %1$s: Discount amount, %2$s: Discount percentage */ |
| 182 |
__( '<strong>%1$s:</strong> to show discount amount<br><strong>%2$s:</strong> to show discount percentage', 'merchant' ), |
| 183 |
'{amount}', |
| 184 |
'{percent}' |
| 185 |
), |
| 186 |
), |
| 187 |
|
| 188 |
array( |
| 189 |
'id' => 'buy_text', |
| 190 |
'type' => 'text', |
| 191 |
'title' => esc_html__( 'Tier format text', 'merchant' ), |
| 192 |
'default' => esc_html__( 'Buy {quantity}, get {discount} off each', 'merchant' ), |
| 193 |
'desc' => __( 'You can use these codes in the content.', 'merchant' ), |
| 194 |
'hidden_desc' => sprintf( |
| 195 |
/* Translators: %1$s: Discount percentage, %2$s: Quantity, %3$s: Discount amount */ |
| 196 |
__( '<strong>%1$s:</strong> to show discount percentage<br><strong>%2$s:</strong> to show the number of items needed to buy to get the discount<br><strong>%3$s:</strong> to show discount amount on each item', 'merchant' ), |
| 197 |
'{percent}', |
| 198 |
'{quantity}', |
| 199 |
'{discount}' |
| 200 |
), |
| 201 |
), |
| 202 |
|
| 203 |
array( |
| 204 |
'id' => 'item_text', |
| 205 |
'type' => 'text', |
| 206 |
'title' => esc_html__( 'Item text', 'merchant' ), |
| 207 |
'default' => esc_html__( 'Per item:', 'merchant' ), |
| 208 |
), |
| 209 |
|
| 210 |
array( |
| 211 |
'id' => 'total_text', |
| 212 |
'type' => 'text', |
| 213 |
'title' => esc_html__( 'Total text', 'merchant' ), |
| 214 |
'default' => esc_html__( 'Total price:', 'merchant' ), |
| 215 |
), |
| 216 |
|
| 217 |
array( |
| 218 |
'id' => 'cart_title_text', |
| 219 |
'type' => 'text', |
| 220 |
'title' => esc_html__( 'Cart item discount title', 'merchant' ), |
| 221 |
'default' => esc_html__( 'Discount', 'merchant' ), |
| 222 |
'desc' => esc_html__( 'This is displayed on the cart page.', 'merchant' ), |
| 223 |
), |
| 224 |
|
| 225 |
array( |
| 226 |
'id' => 'cart_description_text', |
| 227 |
'type' => 'text', |
| 228 |
'title' => esc_html__( 'Cart item discount description', 'merchant' ), |
| 229 |
'default' => esc_html__( 'A discount of {amount} has been applied.', 'merchant' ), |
| 230 |
'desc' => __( 'This is displayed on the cart page. You can use these codes in the content.', 'merchant' ), |
| 231 |
'hidden_desc' => sprintf( |
| 232 |
/* Translators: %1$s: Discount amount, %2$s: Discount percentage */ |
| 233 |
__( '<strong>%1$s:</strong> to show discount amount<br><strong>%2$s:</strong> to show discount percentage', 'merchant' ), |
| 234 |
'{amount}', |
| 235 |
'{percent}' |
| 236 |
), |
| 237 |
), |
| 238 |
|
| 239 |
// style settings |
| 240 |
array( |
| 241 |
'id' => 'title_font_size', |
| 242 |
'type' => 'range', |
| 243 |
'title' => esc_html__( 'Title font size', 'merchant' ), |
| 244 |
'min' => 0, |
| 245 |
'max' => 100, |
| 246 |
'step' => 1, |
| 247 |
'unit' => 'px', |
| 248 |
'default' => 16, |
| 249 |
), |
| 250 |
|
| 251 |
array( |
| 252 |
'id' => 'title_font_weight', |
| 253 |
'type' => 'select', |
| 254 |
'title' => esc_html__( 'Title font weight', 'merchant' ), |
| 255 |
'options' => array( |
| 256 |
'lighter' => esc_html__( 'Light', 'merchant' ), |
| 257 |
'normal' => esc_html__( 'Normal', 'merchant' ), |
| 258 |
'bold' => esc_html__( 'Bold', 'merchant' ), |
| 259 |
), |
| 260 |
'default' => 'normal', |
| 261 |
), |
| 262 |
|
| 263 |
array( |
| 264 |
'id' => 'title_text_color', |
| 265 |
'type' => 'color', |
| 266 |
'title' => esc_html__( 'Title text color', 'merchant' ), |
| 267 |
'default' => '#212121', |
| 268 |
), |
| 269 |
|
| 270 |
array( |
| 271 |
'id' => 'table_item_bg_color', |
| 272 |
'type' => 'color', |
| 273 |
'title' => esc_html__( 'Choose background color', 'merchant' ), |
| 274 |
'default' => '#fcf0f1', |
| 275 |
), |
| 276 |
|
| 277 |
array( |
| 278 |
'id' => 'table_item_border_color', |
| 279 |
'type' => 'color', |
| 280 |
'title' => esc_html__( 'Choose border color', 'merchant' ), |
| 281 |
'default' => '#d83b3b', |
| 282 |
), |
| 283 |
|
| 284 |
array( |
| 285 |
'id' => 'table_item_text_color', |
| 286 |
'type' => 'color', |
| 287 |
'title' => esc_html__( 'Choose text color', 'merchant' ), |
| 288 |
'default' => '#3c434a', |
| 289 |
), |
| 290 |
|
| 291 |
array( |
| 292 |
'id' => 'table_label_bg_color', |
| 293 |
'type' => 'color', |
| 294 |
'title' => esc_html__( 'Choose label background color', 'merchant' ), |
| 295 |
'default' => '#d83b3b', |
| 296 |
), |
| 297 |
|
| 298 |
array( |
| 299 |
'id' => 'table_label_text_color', |
| 300 |
'type' => 'color', |
| 301 |
'title' => esc_html__( 'Choose label text color', 'merchant' ), |
| 302 |
'default' => '#ffffff', |
| 303 |
), |
| 304 |
), |
| 305 |
), |
| 306 |
), |
| 307 |
'default' => array( |
| 308 |
array( |
| 309 |
'layout' => 'offer-details', |
| 310 |
'min_quantity' => 2, |
| 311 |
'discount' => 10, |
| 312 |
'discount_type' => 'fixed_discount', |
| 313 |
), |
| 314 |
), |
| 315 |
), |
| 316 |
), |
| 317 |
) ); |
| 318 |
|
| 319 |
// Shortcode |
| 320 |
$merchant_module_id = Merchant_Volume_Discounts::MODULE_ID; |
| 321 |
Merchant_Admin_Options::create( array( |
| 322 |
'module' => $merchant_module_id, |
| 323 |
'title' => esc_html__( 'Use shortcode', 'merchant' ), |
| 324 |
'fields' => array( |
| 325 |
array( |
| 326 |
'id' => 'use_shortcode', |
| 327 |
'type' => 'switcher', |
| 328 |
'title' => __( 'Use shortcode', 'merchant' ), |
| 329 |
'default' => 0, |
| 330 |
), |
| 331 |
array( |
| 332 |
'type' => 'info', |
| 333 |
'id' => 'shortcode_info', |
| 334 |
'content' => esc_html__( 'If you are using a page builder or a theme that supports shortcodes, then you can output the module using the shortcode above. This might be useful if, for example, you find that you want to control the position of the module output more precisely than with the module settings. Note that the shortcodes can only be used on single product pages.', 'merchant' ), |
| 335 |
), |
| 336 |
array( |
| 337 |
'id' => 'shortcode_text', |
| 338 |
'type' => 'text_readonly', |
| 339 |
'title' => esc_html__( 'Shortcode text', 'merchant' ), |
| 340 |
'default' => '[merchant_module_' . str_replace( '-', '_', $merchant_module_id ) . ']', |
| 341 |
'condition' => array( 'use_shortcode', '==', '1' ), |
| 342 |
), |
| 343 |
), |
| 344 |
) ); |
| 345 |
|