Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Advanced Order Numbers for WooCommerce
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WooCommerce
Advanced Order Numbers for WooCommerce
Commits
e768a4e3
Commit
e768a4e3
authored
9 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Implement generic support for invoice plugins
parent
dd6f25fb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ordernumbers_woocommerce.php
+37
-73
37 additions, 73 deletions
ordernumbers_woocommerce.php
with
37 additions
and
73 deletions
ordernumbers_woocommerce.php
+
37
−
73
View file @
e768a4e3
...
...
@@ -41,7 +41,10 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
add_action
(
'woocommerce_admin_field_ordernumber_variables'
,
array
(
$this
,
'admin_field_variables'
)
);
add_action
(
'pre_update_option_ordernumber_variables'
,
array
(
$this
,
'update_option_variables'
));
// THIRD-PARTY PLUGIN SUPPORT
// Install hooks for third-party plugin support:
$this
->
thirdparty_invoicenumber_init
();
// Support for specific plugins:
$this
->
thirdparty_wpo_wcpdf_init
();
}
...
...
@@ -298,82 +301,43 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic {
}
/** ************************************************************
* Support for automatic extension updates
** ************************************************************/
public
function
update_access_check
()
{
$ordernumber
=
$_POST
[
'order_number'
];
$orderpass
=
$_POST
[
'order_pass'
];
$json
=
$this
->
helper
->
ajax_counter_delete
(
$_POST
[
'nrtype'
],
$_POST
[
'counter'
]);
wp_send_json
(
$json
);
// THIRD-PARTY PLUGIN SUPPORT
/** ****************************************************************
* Generic Invoice Number handling for third-party invoice plugins
** ****************************************************************
*
* - Filter woocommerce_generate_invoice_number($default, $order) to create the invoice number
* - Filter woocommerce_invoice_number($default, $orderID) to retrieve the
* invoice number (also create the invoice number if it does not yet exist)
*/
protected
function
thirdparty_invoicenumber_init
()
{
// The filter to actually return the order number for the given order
add_filter
(
'woocommerce_generate_invoice_number'
,
array
(
&
$this
,
'thirdparty_create_invoicenumber'
),
10
,
2
/*<= Also get the order object! */
);
add_filter
(
'woocommerce_invoice_number'
,
array
(
&
$this
,
'thirdparty_get_invoicenumber'
),
10
,
2
/*<= Also get the order ID! */
);
}
public
function
checkUpdateAccess
(
$order_number
,
$order_pass
,
$json
=
array
())
{
// First, extract the update server URL from the manifest, then load
// the update XML from the update server, extract the download URL,
// append the order number and password and check whether access is
// possible.
$json
[
'success'
]
=
FALSE
;
if
(
isset
(
$this
->
_xmlFile
))
{
$xmlfile
=
$this
->
_xmlFile
;
/**
* Callback function for WooThemes PDF Invoices to generate an invoice number for an order
* The hook to customize invoice numbers (requests the invoice number from the database;
* creates a new invoice number if no entry exists in the database)
*/
function
thirdparty_create_invoicenumber
(
$default
,
$order
)
{
return
$this
->
get_or_create_number
(
$default
,
$order
,
'invoice'
);
}
function
thirdparty_get_invoicenumber
(
$default
,
$orderid
)
{
if
(
get_option
(
'customize_invoice'
,
'no'
)
!=
'no'
)
{
$_of
=
new
WC_Order_Factory
();
$order
=
$_of
->
get_order
(
$orderid
);
$number
=
$this
->
get_or_create_number
(
$orderid
,
$order
,
'invoice'
);
return
$number
;
}
else
{
// VM 2 does not set the _xmlFile property, so construct it manually
$xmlfile
=
JPATH_SITE
.
'/plugins/'
.
$this
->
_type
.
'/'
.
$this
->
_name
.
'/'
.
$this
->
_name
.
'.xml'
;
return
$default
;
}
$xml
=
simplexml_load_file
(
$xmlfile
);
if
(
!
$xml
||
!
isset
(
$xml
->
updateservers
))
{
JFactory
::
getApplication
()
->
enqueueMessage
(
JText
::
sprintf
(
'OPENTOOLS_XMLMANIFEST_ERROR'
,
$this
->
_xmlFile
),
'error'
);
return
$json
;
}
$updateservers
=
$xml
->
updateservers
;
foreach
(
$updateservers
->
children
()
as
$server
)
{
if
(
$server
->
getName
()
!=
'server'
)
{
JFactory
::
getApplication
()
->
enqueueMessage
(
JText
::
sprintf
(
'OPENTOOLS_XMLMANIFEST_ERROR'
,
$this
->
_xmlFile
),
'error'
);
continue
;
}
$updateurl
=
html_entity_decode
((
string
)
$server
);
$updatescript
=
simplexml_load_file
(
$updateurl
);
if
(
!
$updatescript
)
{
JFactory
::
getApplication
()
->
enqueueMessage
(
JText
::
sprintf
(
'OPENTOOLS_UPDATESCRIPT_ERROR'
,
$updateurl
),
'error'
);
continue
;
}
$urls
=
$updatescript
->
xpath
(
'/updates/update/downloads/downloadurl'
);
while
(
list
(
,
$node
)
=
each
(
$urls
))
{
$downloadurl
=
(
string
)(
$node
);
if
(
$order_number
)
{
$downloadurl
.
=
(
parse_url
(
$downloadurl
,
PHP_URL_QUERY
)
?
'&'
:
'?'
)
.
'order_number='
.
urlencode
(
$order_number
);
}
if
(
$order_pass
)
{
$downloadurl
.
=
(
parse_url
(
$downloadurl
,
PHP_URL_QUERY
)
?
'&'
:
'?'
)
.
'order_pass='
.
urlencode
(
$order_pass
);
}
$downloadurl
.
=
(
parse_url
(
$downloadurl
,
PHP_URL_QUERY
)
?
'&'
:
'?'
)
.
'check_access=1'
;
$headers
=
get_headers
(
$downloadurl
);
list
(
$version
,
$status_code
,
$msg
)
=
explode
(
' '
,
$headers
[
0
],
3
);
// Check the HTTP Status code
switch
(
$status_code
)
{
case
200
:
$json
[
'success'
]
=
TRUE
;
JFactory
::
getApplication
()
->
enqueueMessage
(
$msg
,
'message'
);
$this
->
setupUpdateCredentials
(
$order_number
,
$order_pass
);
break
;
default
:
JFactory
::
getApplication
()
->
enqueueMessage
(
$msg
,
'error'
);
// Clear the credentials...
$this
->
setupUpdateCredentials
(
""
,
""
);
break
;
}
$this
->
setAndSaveParams
(
array
(
'update_credentials_checked'
=>
$json
[
'success'
],
'order_number'
=>
$order_number
,
'order_pass'
=>
$order_pass
,
));
}
}
return
$json
;
}
}
/** ************************************************************
* Support for WPO WooCommerce PDF Invoices and Packaging Slips
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment