-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariation-collection.php
More file actions
executable file
·156 lines (130 loc) · 4.95 KB
/
variation-collection.php
File metadata and controls
executable file
·156 lines (130 loc) · 4.95 KB
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
150
151
152
153
154
155
156
<?php
/**
* Plugin Name: Variation Collection
* Version: 1.0.0
* Plugin URI: https://tareknabil.net/variation-collection/
* Description: WooCommerce Extension to add custom variation cololection for each product variation.
* Author: Tarek Nabil
* Author URI: https://tareknabil.net
* Requires at least: 4.4.0
* Tested up to: 5.4.2
*
* Text Domain: variation_collection
* Domain Path: /languages
*
* @package WordPress
* @author Tarek Nabil
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'variation_collection' ) ) {
/**
* Main Class.
*/
class variation_collection {
/**
* Plugin version.
*
* @var string
*/
const VERSION = '1.0.0';
/**
* Instance of this class.
*
* @var object
*/
protected static $instance = null;
/**
* Return an instance of this class.
*
* @return object single instance of this class.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', array( $this, 'fallback_notice' ) );
} else {
$this->load_plugin_textdomain();
$this->includes();
}
add_action('woocommerce_after_single_product_summary', array( 'Variation_Collection_Functionality', 'variation_collection_add_custom_variations'), 19 );
add_action( 'woocommerce_variation_options_pricing', array( 'Variation_Collection_Functionality','variation_collection_add_select_input'), 10, 3 );
add_action( 'woocommerce_save_product_variation', array( 'Variation_Collection_Functionality','variation_collection_save_data'), 10, 2 );
add_filter( 'woocommerce_available_variation', array( 'Variation_Collection_Functionality','variation_collection_add_data') );
add_action( 'wp_enqueue_scripts', array( 'Variation_Collection_Functionality','enqueue_js_scripts') );
add_filter('variation_collection_products_heading',function(){
if(get_option('variation_collection_section_title')){
return get_option('variation_collection_section_title');
}else{
return __( 'Shop The Collection', 'variation_collection' ) ;
}
},1);
//Add 2 Filters to Variation collection column to the exporter and the exporter column menu.
add_filter( 'woocommerce_product_export_column_names', array('Variation_Collection_Functionality','add_export_column') );
add_filter( 'woocommerce_product_export_product_default_columns', array('Variation_Collection_Functionality','add_export_column' ));
// Filter to add the data
add_filter( 'woocommerce_product_export_product_column_variation_collection', array('Variation_Collection_Functionality','add_export_data'), 10, 2 );
// Add filter to register the 'Variation Collection' column in the importer.
add_filter( 'woocommerce_csv_product_import_mapping_options', array('Variation_Collection_Functionality','add_column_to_importer') );
//Filter to add automatic mapping support for 'Custom Column'.
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', array('Variation_Collection_Functionality','add_column_to_mapping_screen') );
//Add filter to process the data read from the CSV file.
add_filter( 'woocommerce_product_import_pre_insert_product_object', array('Variation_Collection_Functionality','process_import'), 10, 2 );
}
/**
* Method to call and run all the things that you need to fire when your plugin is activated.
*
*/
public static function activate() {
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', array( 'variation_collection', 'fallback_notice' ) );
}
}
/**
* Method to includes our dependencies.
*
* @var string
*/
public function includes() {
include_once 'includes/variation-collection-functionality.php';
}
/**
* Load the plugin text domain for translation.
*
* @access public
* @return bool
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'wepb_plugin_locale', get_locale(), 'variation_collection' );
load_plugin_textdomain( 'variation_collection', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
return true;
}
/**
* Fallback notice.
*
* We need some plugins to work, and if any isn't active we'll show you!
*/
public function fallback_notice() {
echo '<div class="error">';
echo '<p>' . __( '<strong>Variation Collection Plugin</strong> is active now but not functional, Please install and activate <strong>WooCommerce</strong> plugin to make it effective.', 'variationtion_collection' ) . '</p>';
echo '</div>';
}
}
}
/**
* Hook to run when your plugin is activated
*/
register_activation_hook( __FILE__, array( 'variation_collection', 'activate' ) );
/**
* Initialize the plugin.
*/
add_action( 'plugins_loaded', array( 'variation_collection', 'get_instance' ) );