Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Shipping by Rules for WooCommerce
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
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
Shipping by Rules for WooCommerce
Commits
a485d27a
Commit
a485d27a
authored
9 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Fix custom function calls (merged fixed from VirtueMart's copy)
parent
016f92ea
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
library/rules_shipping_framework.php
+16
-19
16 additions, 19 deletions
library/rules_shipping_framework.php
with
16 additions
and
19 deletions
library/rules_shipping_framework.php
+
16
−
19
View file @
a485d27a
...
...
@@ -167,6 +167,10 @@ class RulesShippingFramework {
return
array
();
}
function
getCustomFunctionDefinitions
()
{
return
$this
->
custom_functions
;
}
/** @tag system-specific
* @function printWarning()
* Print a warning in the system-specific way.
...
...
@@ -203,22 +207,14 @@ class RulesShippingFramework {
*/
public
function
setup
()
{
$custfuncdefs
=
$this
->
getCustomFunctions
();
// Loop through the return values of all plugins:
foreach
(
$custfuncdefs
as
$custfuncs
)
{
if
(
empty
(
$custfuncs
))
continue
;
if
(
!
is_array
(
$custfuncs
))
{
$this
->
warning
(
'OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY'
);
}
// Now loop through all custom function definitions of this plugin
// If a function was registered before, print a warning and use the first definition
foreach
(
$custfuncs
as
$fname
=>
$func
)
{
if
(
isset
(
$this
->
custom_functions
[
$fname
]))
{
$this
->
warning
(
'OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED'
,
$fname
);
}
else
{
$this
->
debug
(
"Defining custom function
$fname
"
);
$this
->
custom_functions
[
strtolower
(
$fname
)]
=
$func
;
}
// Now loop through all custom function definitions of this plugin
// If a function was registered before, print a warning and use the first definition
foreach
(
$custfuncdefs
as
$fname
=>
$func
)
{
if
(
isset
(
$this
->
custom_functions
[
$fname
])
&&
$this
->
custom_functions
[
$fname
]
!=
$custfuncs
[
$fname
])
{
$this
->
warning
(
'OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED'
,
$fname
);
}
else
{
$this
->
debug
(
"Defining custom function
$fname
"
);
$this
->
custom_functions
[
strtolower
(
$fname
)]
=
$func
;
}
}
}
...
...
@@ -644,7 +640,7 @@ class ShippingRule {
/* In the advanced version, all conditions and costs can be given as a full mathematical expression */
/* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */
$rulepart
=
trim
(
$rulepart
);
if
(
empty
(
$rulepart
))
return
;
if
(
!
isset
(
$rulepart
)
||
$rulepart
===
''
)
return
;
// Special-case the name assignment, where we don't want to interpret the value as an arithmetic expression!
...
...
@@ -831,9 +827,10 @@ class ShippingRule {
$func
=
strtolower
(
$function
);
// Check if we have a custom function definition and use that if so.
// This is done first to allow plugins to override even built-in functions!
if
(
isset
(
$this
->
plugin
->
custom_functions
[
$func
]))
{
$customfunctions
=
$this
->
framework
->
getCustomFunctionDefinitions
();
if
(
isset
(
$customfunctions
[
$func
]))
{
$this
->
framework
->
debug
(
"Evaluating custom function
$function
, defined by a plugin"
);
return
call_user_func
_array
(
$this
->
plugin
->
custom
_
functions
[
$func
],
$args
,
$this
);
return
call_user_func
(
$
customfunctions
[
$func
],
$args
,
$this
);
}
// Functions with no argument:
...
...
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