Commit 3c37894d authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Initial commit, raw plugin structure, assigning random order numbers and...

Initial commit, raw plugin structure, assigning random order numbers and retrieving them again works...
parents
=== Advanced Ordernumbers ===
Contributors: opetools
Tags: WooCommerce, Order numbers, orders
Requires at least: 4.0
Tested up to: 4.1.1
Stable tag: trunk
License: GPLv2
Freely customize order numbers in WooCommerce. Lots of variables and counter settings can be used in the order number format.
== Description ==
Freely customize order numbers in WooCommerce. Lots of variables and counter settings can be used in the order number format.
\ No newline at end of file
<div class="wrap">
<h2>OpenTools Advanced ordernumbers</h2>
<form method="post" action="options.php">
<?php @settings_fields('create_ordernumber-group'); ?>
<?php @do_settings_fields('create_ordernumber-group'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="customize_ordernumber">Customize Order Numbers</label></th>
<td><input type="text" name="customize_ordernumber" id="customize_ordernumber" value="<?php echo get_option('customize_ordernumber'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="ordernumber_format">Order Number Format</label></th>
<td><input type="text" name="ordernumber_format" id="ordernumber_format" value="<?php echo get_option('ordernumber_format'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="ordernumber_counter_scope">Scope of the Counter</label></th>
<td><input type="text" name="ordernumber_counter_scope" id="ordernumber_counter_scope" value="<?php echo get_option('ordernumber_counter_scope'); ?>" /></td>
</tr>
</table>
<?php @submit_button(); ?>
</form>
</div>
\ No newline at end of file
<?php
/**
* Plugin Name: Advanced Ordernumbers
* Plugin URI: http://open-tools.net/WooCommerce/Advanced-Ordernumbers.php
* Description: Lets the user freely configure the order numbers in WooCommerce.
* Version: 0.1.0
* Author: Open Tools, Reinhold Kainhofer
* Author URI: http://open-tools.net
* Text Domain: woocommerce-advanced-ordernumbers
* Domain Path:
* License: GPL2+
WC requires at least: 2.2
WC tested up to: 2.3
*/
/**
* The structure of this plugin follows the tutorial:
* http://www.yaconiello.com/blog/how-to-write-wordpress-plugin/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Check if WooCommerce is active
**/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Put your plugin code here
// Load the language files
load_plugin_textdomain('your-unique-name', false, basename( dirname( __FILE__ ) ) . '/languages' );
if (!class_exists("OpenToolsOrdernumbers")) {
class OpenToolsOrdernumbers {
/**
* Construct the plugin object
*/
public function __construct()
{
add_action ('woocommerce_order_number', array(&$this, 'get_ordernumber'));
add_action( 'admin_init', array(&$this, 'admin_init'));
add_action( 'admin_menu', array(&$this, 'admin_menu'));
// register actions
}
/**
* Activate the plugin
*/
public static function activate()
{
// Do nothing
}
/**
* Deactivate the plugin
*/
public static function deactivate()
{
// Do nothing
}
/**
* hook into WP's admin_init action hook
*/
public function admin_init()
{
// Set up the settings for this plugin
$this->init_settings();
// Possibly do additional admin_init tasks
}
/**
* Initialize some custom settings
*/
public function init_settings()
{
// register the settings for this plugin
register_setting('opentools-ordernumber-group', 'customize_ordernumber');
register_setting('opentools-ordernumber-group', 'ordernumber_format');
register_setting('opentools-ordernumber-group', 'ordernumber_counter_scope');
}
/**
* add a menu
*/
public function add_menu()
{
add_options_page('Advanced Ordernumber Plugin Settings', 'OpenTools Advanced Ordernumbers',
'manage_options', 'opentools-ordernumbers', array(&$this, 'plugin_settings_page'));
} // END public function add_menu()
/**
* Menu Callback
*/
public function plugin_settings_page()
{
// if(!current_user_can('manage_options'))
// {
// wp_die(__('You do not have sufficient permissions to access this page.'));
// }
// Render the settings template
include(sprintf("%s/templates/settings.php", dirname(__FILE__)));
}
/**
* The hook to customize order numbers (requests the order number from the database; creates a new ordernumber if no entry exists in the database)
*/
function get_ordernumber($orderid, $order) {
$stored_number = get_post_meta( $orderid, 'ordernumber', 'true');
if (!empty($stored_number)) {
return $stored_number;
} else {
// create a new one (if this is a new order, otherwise we don't have/generate a number!)
$number = $this->create_ordernumber($orderid, $order);
update_post_meta( $orderid, 'ordernumber', $number );
return $number;
}
}
function create_ordernumber($orderid, $order) {
$rnd=rand(100, 1000000);
return "Order-$orderid-Number-$rnd";
}
}
}
if (class_exists("OpenToolsOrdernumbers")) {
// Installation and uninstallation hooks
register_activation_hook(__FILE__, array('OpenToolsOrdernumbers', 'activate'));
register_deactivation_hook(__FILE__, array('OpenToolsOrdernumbers', 'deactivate'));
// instantiate the plugin class
$ordernumber_plugin = new OpenToolsOrdernumbers();
// Add a link to the settings page onto the plugin page
if(isset($ordernumber_plugin)) {
// Add the settings link to the plugins page
function plugin_settings_link($links)
{
$settings_link = '<a href="options-general.php?page=wp_plugin_template">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'plugin_settings_link');
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment