-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdispensary-coupons.php
130 lines (110 loc) · 3.58 KB
/
dispensary-coupons.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
<?php
/**
* Plugin Name: CannaBiz Coupons
* Plugin URI: https://cannabizsoftware.com/
* Description: Easily add and display coupons for your dispensary or delivery service business.
* Version: 2.0
* Author: CannaBiz Software
* Author URI: https://cannabizsoftware.com/
* Text Domain: wpd-coupons
* Domain Path: /languages
*
* @package WPD_Coupons
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
* Load scripts and styles
*
* @since 1.0.0
* @return void
*/
function wpd_coupons_load_scripts() {
wp_enqueue_style( 'wpd-coupons', plugin_dir_url( __FILE__ ) . 'css/style.css' );
}
add_action( 'wp_enqueue_scripts', 'wpd_coupons_load_scripts' );
/**
* Load admin scripts and styles
*
* @since 1.1.0
* @return void
*/
function wpd_coupons_load_admin_scripts() {
wp_enqueue_style( 'wpd-coupons', plugin_dir_url( __FILE__ ) . 'css/admin.css' );
}
add_action( 'admin_enqueue_scripts', 'wpd_coupons_load_admin_scripts' );
/**
* The file responsible for creating custom helper functions
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/dispensary-coupons-helper-functions.php';
/**
* The class responsible for creating custom permalinks
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/class-dispensary-coupons-permalinks.php';
/**
* The file responsible for creating coupons post type.
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/dispensary-coupons-post-type.php';
/**
* The file responsible for creating coupons widget.
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/dispensary-coupons-widget.php';
/**
* The file responsible for creating coupons shortcode.
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/dispensary-coupons-shortcode.php';
/**
* The file responsible for creating coupons metabox.
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/dispensary-coupons-metabox.php';
/**
* The file responsible for adding columns to the Coupons admin screen.
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/dispensary-coupons-admin-screens.php';
/**
* The file responsible for running on plugin activation.
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/dispensary-coupons-activation.php';
/**
* Check to make sure WP Dispensary is active
*/
if ( in_array( 'wp-dispensary/wp-dispensary.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
/**
* Add 'Coupons' link to WPD admin menu
*
* @return void
*/
function dispensary_coupons_add_admin_menu() {
add_submenu_page( 'wpd-settings', 'WP Dispensary\'s Coupons', 'Coupons', 'manage_options', 'edit.php?post_type=coupons', NULL );
}
add_action( 'admin_menu', 'dispensary_coupons_add_admin_menu', 5 );
}
/**
* Add Coupons to the bottom of the Pricing data table
*
* @since 1.4.0
* @return string
*/
function wpd_coupons_pricing() {
global $post;
$product_id = $post->ID;
$args = [
'meta_key' => 'selected_product',
'meta_value' => $product_id,
'post_type' => 'coupons',
'posts_per_page' => -1
];
$product_coupons = new WP_Query( $args );
if ( $product_coupons->have_posts() ) :
echo '<td class="wpd-coupons" colspan="7"><span>' . esc_attr__( 'Coupons', 'wpd-coupons' ) . '</span> ';
while ( $product_coupons->have_posts() ) : $product_coupons->the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
echo '</td>';
endif;
// Reset Post Data
wp_reset_postdata();
}
add_action( 'wpd_pricingoutput_bottom', 'wpd_coupons_pricing', 20 );