-
Notifications
You must be signed in to change notification settings - Fork 1
/
woocommerce-apply-order-discount.php
65 lines (59 loc) · 2.49 KB
/
woocommerce-apply-order-discount.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
<?php
/*
Plugin Name: WooCommerce Admin Apply Order Discount
Version: 1.1.2
Plugin URI: https://github.com/scrobbleme/woocommerce-apply-order-discount
Description: This plugin allows administrators to apply discounts on orders from the administration panel.
Author: MOEWE GbR - Adrian Mörchen, Markus Weigelt
Text Domain: woocommerce-apply-order-discount
Domain Path: /languages/
Author URI: https://www.moewe.io
*/
add_action('add_meta_boxes', 'scrobble_me_wcaod_add_apply_discount_container', 10, 2);
add_action('admin_enqueue_scripts', 'scrobble_me_wcaod_enque_scripts');
function scrobble_me_wcaod_enque_scripts() {
wp_enqueue_script('scrobble_me_wcaod-js', plugins_url('js/woocommerce-apply-order-discount.js', __FILE__), array(), '1.1', false);
wp_localize_script('scrobble_me_wcaod-js', 'scrobble_me_wcaod_locales', array(
'confirm_apply_discount' => __('Are you sure? Applying the discount may overwrite existing discounts.', 'woocommerce-apply-order-discount'),
'apply_success_message' => __('Please press "Calc Taxes" and "Calc Totals" and save the order afterwards.', 'woocommerce-apply-order-discount')));
}
/**
* @param $post_type string
* @param $post WP_Post
*/
function scrobble_me_wcaod_add_apply_discount_container($post_type, $post) {
if ($post_type != 'shop_order') {
return;
}
$order = new WC_Order($post->ID);
if (!$order->is_editable()) {
return;
}
add_meta_box('woocommerce-apply-coupon-later-container', __('Apply Discount', 'woocommerce-apply-order-discount'),
'scrobble_me_wcaod_create_apply_discount_container', 'shop_order', 'side');
}
function scrobble_me_wcaod_create_apply_discount_container() {
?>
<ul id="woocommerce-apply-discount" class="woocommerce-apply-discount">
<li>
<input type="number" name="discount" min="0" step="1"
placeholder="<?php _e('Discount in %', 'woocommerce-apply-order-discount') ?>"/>
</li>
<li>
<button
class="button apply_discount"><?php _e('Apply Discount', 'woocommerce-apply-order-discount'); ?></button>
</li>
</ul>
<?php
}
/**
* Check for plugin updates
*/
require __DIR__ . '/libs/plugin-update-checker-3.1/plugin-update-checker.php';
$updater = PucFactory::buildUpdateChecker(
'https://raw.githubusercontent.com/moewe-io/woocommerce-apply-order-discount/stable/updater.json',
__FILE__,
'woocommerce-apply-order-discount',
24
);
$updater->throttleRedundantChecks = true;