Commit 46c54eda authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

First versions of template extension example

parent 9d26cb88
This diff is collapsed.
BASE=YOUR_PLUGIN_NAME
PLATTFORM=woocommerce
VENDOR=opentools
VERSION=1.0
DIR = $(shell pwd)
BUILDDIR=.build/
PLUGINFILES=$(BASE).php readme.txt LICENSE.txt
TRANSLATIONS=
ZIPFILE=$(PLATTFORM)-$(BASE)-v$(VERSION).zip
all: zip
zip: $(PLUGINFILES) $(TRANSLATIONS) $(ADVANCEDFILES) $(INDEXFILES)
@echo "Packing all files into distribution file $(ZIPFILE):"
@zip -r $(ZIPFILE) $(PLUGINFILES) $(TRANSLATIONS) $(INDEXFILES) $(FIELDS)
clean:
rm -f $(ZIPFILE)
zip: $(PLUGINFILES) $(TRANSLATIONS)
@echo "Packing plugin into distribution file $(ZIPFILE):"
@mkdir -p $(BUILDDIR)/$(BASE)
@cp --parents -r $(PLUGINFILES) $(TRANSLATIONS) $(BUILDDIR)/$(BASE)/
cd $(BUILDDIR) && zip -r $(DIR)/$(ZIPFILE) $(BASE)
cd $(DIR)
clean:
rm -rf $(ZIPFILE) $(BUILDDIR)
<?php
/**
* Plugin Name: YOUR_PLUGIN_NAME extension plugin for OpenTools Basic/Advanced Ordernumbers for WooCommerce
* Plugin URI: http://open-tools.net/woocommerce/advanced-ordernumbers-for-woocommerce.html
* Description: A sample template for an extension plugin for the OpenTools Basic / Advanced Ordernumber for WooCommerce plugin. This extension plugin can provide additional variables, modify existing variables and post-process the generated numbers.
* Version: 1.0
* Author: Open Tools
* Author URI: http://open-tools.net
* Text Domain: woocommerce-ordernumbers-extension-YOUR_PLUGIN_NAME
* License: GPL2+
* Network: true
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** Filter to add variables to be used in the number formats
* You can add new variables to the $reps array or modify existing ones. They will be directly
* available in all formats. This filter will be called whenever the ordernumber plugin creates a
* number. All built-in variables are already set in the $reps variable, so you can even override
* the built-in variables by changing $reps accordingly.
* $details contains the order details
* $nrtype is "ordernumber" or "invoice"
*
* Returns the new array of variables (even if unmodified!)
*/
add_filter('opentools_ordernumber_replacements', "ordernumber_replacements_YOUR_PLUGIN_NAME", 10, 3);
ordernumber_replacements_YOUR_PLUGIN_NAME($reps, $details, $nrtype) {
$userid = $details->get_user_id();
// Case 1: Return the number of orders this user has already posted (+1,
// because the current order is not yet registered with WC!)
$reps['[userordercount]'] = wc_get_customer_order_count($userid)+1;
// Case 2: Add a [Type] variable that holds either "ordernumber" or "invoice"
$reps['[type]'] = $nrtype;
// Case 3: Modify an existing variable:
$reps['[second]'] = $reps['[second]'] + 15;
return $reps;
}
#!/bin/bash
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARGC=$#
if [ $ARGC -lt 1 ]; then
echo "Usage: $0 YourPluginName"
echo "Create a proper plugin for the Ordernumber plugin from the provided template"
exit -1;
fi
name=$1
pluginname=${name,,}
pLUGINNAME=${name,}
Pluginname=${name^}
PLUGINNAME=${name^^}
echo "Plugin name=$name, pluginname=$pluginname, pLUGINNAME=$pLUGINNAME, Pluginname=$Pluginname, PLUGINNAME=$PLUGINNAME"
mkdir -p $pluginname/
sed "s/YOUR_PLUGIN_NAME/$Pluginname/g" $SRCDIR/YOUR_PLUGIN_NAME.php > $pluginname/$pluginname.php
sed "s/YOUR_PLUGIN_NAME/$Pluginname/g" $SRCDIR/readme.txt > $pluginname/readme.txt
sed "s/YOUR_PLUGIN_NAME/$pluginname/g" $SRCDIR/Makefile > $pluginname/Makefile
cp $SRCDIR/LICENSE.txt $pluginname/LICENSE.txt
echo "Created new plugin '$pluginname' for the Ordernumber plugin. Please adjust the plugin's readme.txt, the ordernumber_replacements_$pluginname function and all copyright statements."
\ No newline at end of file
=== YOUR_PLUGIN_NAME extension for OpenTools Ordernumbers for WooCommerce ===
Plugin Name: YOUR_PLUGIN_NAME extension for OpenTools Ordernumbers for WooCommerce
Contributors: opentools
Tags: WooCommerce, Order numbers, orders
Requires at least: 4.0
Tested up to: 4.5
Stable tag: 1.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl.html
Extension plugin for the OpenTools Basic/Advanced Ordernumbers for WooCommerce.
Custom variables can be provided.
== Description ==
This extension plugin is a template to show how custom plugins can add new variables
for use in the order/invoice numbers generated by the OpenTools Basic/Advanced
Ordernumbers plugin for WooCommerce.
For the full documentation of both the basic and the advanced ordernumbers plugin for WooCommerce, see:
http://open-tools.net/documentation/advanced-order-numbers-for-woocommerce.html
== Installation ==
1. To install the plugin, either:
1. use WordPress' plugin manager to find it in the WordPress plugin directory and directly install it from the WP plugin manager, or
1. use WordPress' plugin manager to upload the plugin's zip file.
1. After installation, activate the plugin through the 'Plugins' menu in WordPress
1. Enable the plugin's functionality in the WooCommerce settings (tab "Checkout" -> "Order numbers")
== Frequently Asked Questions ==
None yet.
== Screenshots ==
== Changelog ==
= 1.0 =
* Initial release
== Upgrade Notice ==
No upgrades yet.
This diff is collapsed.
BASE=user_order_count
PLATTFORM=woocommerce
VENDOR=opentools
VERSION=1.0
PLUGINFILES=$(BASE).php readme.txt LICENSE.txt
TRANSLATIONS=
ZIPFILE=$(PLATTFORM)-$(BASE)-v$(VERSION).zip
all: zip
zip: $(PLUGINFILES) $(TRANSLATIONS) $(ADVANCEDFILES) $(INDEXFILES)
@echo "Packing all files into distribution file $(ZIPFILE):"
@zip -r $(ZIPFILE) $(PLUGINFILES) $(TRANSLATIONS) $(INDEXFILES) $(FIELDS)
clean:
rm -f $(ZIPFILE)
=== User_order_count extension for OpenTools Ordernumbers for WooCommerce ===
Plugin Name: User_order_count extension for OpenTools Ordernumbers for WooCommerce
Contributors: opentools
Tags: WooCommerce, Order numbers, orders
Requires at least: 4.0
Tested up to: 4.5
Stable tag: 1.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl.html
Extension plugin for the OpenTools Basic/Advanced Ordernumbers for WooCommerce.
Custom variables can be provided.
== Description ==
This extension plugin is a template to show how custom plugins can add new variables
for use in the order/invoice numbers generated by the OpenTools Basic/Advanced
Ordernumbers plugin for WooCommerce.
For the full documentation of both the basic and the advanced ordernumbers plugin for WooCommerce, see:
http://open-tools.net/documentation/advanced-order-numbers-for-woocommerce.html
== Installation ==
1. To install the plugin, either:
1. use WordPress' plugin manager to find it in the WordPress plugin directory and directly install it from the WP plugin manager, or
1. use WordPress' plugin manager to upload the plugin's zip file.
1. After installation, activate the plugin through the 'Plugins' menu in WordPress
1. Enable the plugin's functionality in the WooCommerce settings (tab "Checkout" -> "Order numbers")
== Frequently Asked Questions ==
None yet.
== Screenshots ==
== Changelog ==
= 1.0 =
* Initial release
== Upgrade Notice ==
No upgrades yet.
<?php
/**
* Plugin Name: User_order_count extension plugin for OpenTools Basic/Advanced Ordernumbers for WooCommerce
* Plugin URI: http://open-tools.net/woocommerce/advanced-ordernumbers-for-woocommerce.html
* Description: A sample template for an extension plugin for the OpenTools Basic / Advanced Ordernumber for WooCommerce plugin. This extension plugin can provide additional variables, modify existing variables and post-process the generated numbers.
* Version: 1.0
* Author: Open Tools
* Author URI: http://open-tools.net
* Text Domain: woocommerce-ordernumbers-extension-User_order_count
* License: GPL2+
* Network: true
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** Filter to add variables to be used in the number formats
* You can add new variables to the $reps array or modify existing ones. They will be directly
* available in all formats. This filter will be called whenever the ordernumber plugin creates a
* number. All built-in variables are already set in the $reps variable, so you can even override
* the built-in variables by changing $reps accordingly.
* $details contains the order details
* $nrtype is "ordernumber" or "invoice"
*
* Returns the new array of variables (even if unmodified!)
*/
add_filter('opentools_ordernumber_replacements', "ordernumber_replacements_User_order_count", 10, 3);
ordernumber_replacements_User_order_count($reps, $details, $nrtype) {
$userid = $details->get_user_id();
// Case 1: Return the number of orders this user has already posted (+1,
// because the current order is not yet registered with WC!)
$reps['[userordercount]'] = wc_get_customer_order_count($userid)+1;
// Case 2: Add a [Type] variable that holds either "ordernumber" or "invoice"
$reps['[type]'] = $nrtype;
// Case 3: Modify an existing variable:
$reps['[second]'] = $reps['[second]'] + 15;
return $reps;
}
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