Merge branch 'trunk' into add/e2e-shopper-create-products-api
This commit is contained in:
commit
d9cead9943
|
@ -267,20 +267,21 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
"version": "v5.2.8",
|
||||
"version": "v5.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/console.git",
|
||||
"reference": "864568fdc0208b3eba3638b6000b69d2386e6768"
|
||||
"reference": "058553870f7809087fa80fa734704a21b9bcaeb2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/864568fdc0208b3eba3638b6000b69d2386e6768",
|
||||
"reference": "864568fdc0208b3eba3638b6000b69d2386e6768",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/058553870f7809087fa80fa734704a21b9bcaeb2",
|
||||
"reference": "058553870f7809087fa80fa734704a21b9bcaeb2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"symfony/deprecation-contracts": "^2.1",
|
||||
"symfony/polyfill-mbstring": "~1.0",
|
||||
"symfony/polyfill-php73": "^1.8",
|
||||
"symfony/polyfill-php80": "^1.15",
|
||||
|
@ -344,7 +345,7 @@
|
|||
"terminal"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/console/tree/v5.2.8"
|
||||
"source": "https://github.com/symfony/console/tree/v5.3.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -360,20 +361,87 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-05-11T15:45:21+00:00"
|
||||
"time": "2021-05-26T17:43:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/finder",
|
||||
"version": "v5.2.9",
|
||||
"name": "symfony/deprecation-contracts",
|
||||
"version": "v2.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/finder.git",
|
||||
"reference": "ccccb9d48ca42757dd12f2ca4bf857a4e217d90d"
|
||||
"url": "https://github.com/symfony/deprecation-contracts.git",
|
||||
"reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/ccccb9d48ca42757dd12f2ca4bf857a4e217d90d",
|
||||
"reference": "ccccb9d48ca42757dd12f2ca4bf857a4e217d90d",
|
||||
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627",
|
||||
"reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "2.4-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"function.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "A generic function and convention to trigger deprecation notices",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-03-23T23:28:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/finder",
|
||||
"version": "v5.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/finder.git",
|
||||
"reference": "0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6",
|
||||
"reference": "0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -405,7 +473,7 @@
|
|||
"description": "Finds files and directories via an intuitive fluent interface",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/finder/tree/v5.2.9"
|
||||
"source": "https://github.com/symfony/finder/tree/v5.3.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -421,20 +489,20 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-05-16T13:07:46+00:00"
|
||||
"time": "2021-05-26T12:52:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.22.1",
|
||||
"version": "v1.23.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "c6c942b1ac76c82448322025e084cadc56048b4e"
|
||||
"reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e",
|
||||
"reference": "c6c942b1ac76c82448322025e084cadc56048b4e",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce",
|
||||
"reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -446,7 +514,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.22-dev"
|
||||
"dev-main": "1.23-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -484,7 +552,7 @@
|
|||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1"
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -500,20 +568,20 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-01-07T16:49:33+00:00"
|
||||
"time": "2021-02-19T12:13:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-intl-grapheme",
|
||||
"version": "v1.22.1",
|
||||
"version": "v1.23.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
|
||||
"reference": "5601e09b69f26c1828b13b6bb87cb07cddba3170"
|
||||
"reference": "24b72c6baa32c746a4d0840147c9715e42bb68ab"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/5601e09b69f26c1828b13b6bb87cb07cddba3170",
|
||||
"reference": "5601e09b69f26c1828b13b6bb87cb07cddba3170",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/24b72c6baa32c746a4d0840147c9715e42bb68ab",
|
||||
"reference": "24b72c6baa32c746a4d0840147c9715e42bb68ab",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -525,7 +593,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.22-dev"
|
||||
"dev-main": "1.23-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -565,7 +633,7 @@
|
|||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.22.1"
|
||||
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.23.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -581,20 +649,20 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-01-22T09:19:47+00:00"
|
||||
"time": "2021-05-27T09:17:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-intl-normalizer",
|
||||
"version": "v1.22.1",
|
||||
"version": "v1.23.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
|
||||
"reference": "43a0283138253ed1d48d352ab6d0bdb3f809f248"
|
||||
"reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/43a0283138253ed1d48d352ab6d0bdb3f809f248",
|
||||
"reference": "43a0283138253ed1d48d352ab6d0bdb3f809f248",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8",
|
||||
"reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -606,7 +674,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.22-dev"
|
||||
"dev-main": "1.23-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -649,7 +717,7 @@
|
|||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.22.1"
|
||||
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.23.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -665,20 +733,20 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-01-22T09:19:47+00:00"
|
||||
"time": "2021-02-19T12:13:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.22.1",
|
||||
"version": "v1.23.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "5232de97ee3b75b0360528dae24e73db49566ab1"
|
||||
"reference": "2df51500adbaebdc4c38dea4c89a2e131c45c8a1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/5232de97ee3b75b0360528dae24e73db49566ab1",
|
||||
"reference": "5232de97ee3b75b0360528dae24e73db49566ab1",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2df51500adbaebdc4c38dea4c89a2e131c45c8a1",
|
||||
"reference": "2df51500adbaebdc4c38dea4c89a2e131c45c8a1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -690,7 +758,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.22-dev"
|
||||
"dev-main": "1.23-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -729,7 +797,7 @@
|
|||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.22.1"
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -745,20 +813,20 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-01-22T09:19:47+00:00"
|
||||
"time": "2021-05-27T09:27:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php73",
|
||||
"version": "v1.22.1",
|
||||
"version": "v1.23.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php73.git",
|
||||
"reference": "a678b42e92f86eca04b7fa4c0f6f19d097fb69e2"
|
||||
"reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/a678b42e92f86eca04b7fa4c0f6f19d097fb69e2",
|
||||
"reference": "a678b42e92f86eca04b7fa4c0f6f19d097fb69e2",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fba8933c384d6476ab14fb7b8526e5287ca7e010",
|
||||
"reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -767,7 +835,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.22-dev"
|
||||
"dev-main": "1.23-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -808,7 +876,7 @@
|
|||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php73/tree/v1.22.1"
|
||||
"source": "https://github.com/symfony/polyfill-php73/tree/v1.23.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -824,20 +892,20 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-01-07T16:49:33+00:00"
|
||||
"time": "2021-02-19T12:13:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php80",
|
||||
"version": "v1.22.1",
|
||||
"version": "v1.23.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php80.git",
|
||||
"reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91"
|
||||
"reference": "eca0bf41ed421bed1b57c4958bab16aa86b757d0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dc3063ba22c2a1fd2f45ed856374d79114998f91",
|
||||
"reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/eca0bf41ed421bed1b57c4958bab16aa86b757d0",
|
||||
"reference": "eca0bf41ed421bed1b57c4958bab16aa86b757d0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -846,7 +914,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.22-dev"
|
||||
"dev-main": "1.23-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
|
@ -891,7 +959,7 @@
|
|||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.22.1"
|
||||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.23.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -907,7 +975,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-01-07T16:49:33+00:00"
|
||||
"time": "2021-02-19T12:13:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/service-contracts",
|
||||
|
@ -990,16 +1058,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/string",
|
||||
"version": "v5.2.8",
|
||||
"version": "v5.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/string.git",
|
||||
"reference": "01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db"
|
||||
"reference": "a9a0f8b6aafc5d2d1c116dcccd1573a95153515b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db",
|
||||
"reference": "01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/a9a0f8b6aafc5d2d1c116dcccd1573a95153515b",
|
||||
"reference": "a9a0f8b6aafc5d2d1c116dcccd1573a95153515b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1053,7 +1121,7 @@
|
|||
"utf8"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/string/tree/v5.2.8"
|
||||
"source": "https://github.com/symfony/string/tree/v5.3.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1069,7 +1137,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-05-10T14:56:10+00:00"
|
||||
"time": "2021-05-26T17:43:10+00:00"
|
||||
}
|
||||
],
|
||||
"aliases": [],
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"maxmind-db/reader": "1.6.0",
|
||||
"pelago/emogrifier": "3.1.0",
|
||||
"psr/container": "1.0.0",
|
||||
"woocommerce/action-scheduler": "3.1.6",
|
||||
"woocommerce/action-scheduler": "3.2.0",
|
||||
"woocommerce/woocommerce-admin": "2.3.1",
|
||||
"woocommerce/woocommerce-blocks": "5.1.0"
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "cf10f974b24dd9a696708cc95a0e3d6e",
|
||||
"content-hash": "21b06e63b5f65deec4b635463a10402b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "automattic/jetpack-autoloader",
|
||||
|
@ -493,22 +493,22 @@
|
|||
},
|
||||
{
|
||||
"name": "woocommerce/action-scheduler",
|
||||
"version": "3.1.6",
|
||||
"version": "3.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/woocommerce/action-scheduler.git",
|
||||
"reference": "275d0ba54b1c263dfc62688de2fa9a25a373edf8"
|
||||
"reference": "12c91fd20af0cdfb6107b8db9df78d133f512b04"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/woocommerce/action-scheduler/zipball/275d0ba54b1c263dfc62688de2fa9a25a373edf8",
|
||||
"reference": "275d0ba54b1c263dfc62688de2fa9a25a373edf8",
|
||||
"url": "https://api.github.com/repos/woocommerce/action-scheduler/zipball/12c91fd20af0cdfb6107b8db9df78d133f512b04",
|
||||
"reference": "12c91fd20af0cdfb6107b8db9df78d133f512b04",
|
||||
"shasum": ""
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.6",
|
||||
"woocommerce/woocommerce-sniffs": "0.0.8",
|
||||
"wp-cli/wp-cli": "~1.5.1"
|
||||
"phpunit/phpunit": "^7.5",
|
||||
"woocommerce/woocommerce-sniffs": "0.1.0",
|
||||
"wp-cli/wp-cli": "~2.5.0"
|
||||
},
|
||||
"type": "wordpress-plugin",
|
||||
"extra": {
|
||||
|
@ -526,9 +526,9 @@
|
|||
"homepage": "https://actionscheduler.org/",
|
||||
"support": {
|
||||
"issues": "https://github.com/woocommerce/action-scheduler/issues",
|
||||
"source": "https://github.com/woocommerce/action-scheduler/tree/master"
|
||||
"source": "https://github.com/woocommerce/action-scheduler/tree/3.2.0"
|
||||
},
|
||||
"time": "2020-05-12T16:22:33+00:00"
|
||||
"time": "2021-06-03T16:41:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "woocommerce/woocommerce-admin",
|
||||
|
|
|
@ -64,6 +64,7 @@ abstract class WC_Widget extends WP_Widget {
|
|||
'classname' => $this->widget_cssclass,
|
||||
'description' => $this->widget_description,
|
||||
'customize_selective_refresh' => true,
|
||||
'show_instance_in_rest' => true,
|
||||
);
|
||||
|
||||
parent::__construct( $this->widget_id, $this->widget_name, $widget_ops );
|
||||
|
@ -372,7 +373,7 @@ abstract class WC_Widget extends WP_Widget {
|
|||
}
|
||||
|
||||
// All current filters.
|
||||
if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found, WordPress.CodeAnalysis.AssignmentInCondition.Found
|
||||
if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure, WordPress.CodeAnalysis.AssignmentInCondition.Found
|
||||
foreach ( $_chosen_attributes as $name => $data ) {
|
||||
$filter_name = wc_attribute_taxonomy_slug( $name );
|
||||
if ( ! empty( $data['terms'] ) ) {
|
||||
|
|
|
@ -30,7 +30,8 @@ class WC_Settings_Accounts extends WC_Settings_Page {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
protected function get_settings_for_default_section() {
|
||||
|
||||
$erasure_text = esc_html__( 'account erasure request', 'woocommerce' );
|
||||
$privacy_text = esc_html__( 'privacy page', 'woocommerce' );
|
||||
if ( current_user_can( 'manage_privacy_options' ) ) {
|
||||
|
@ -228,12 +229,10 @@ class WC_Settings_Accounts extends WC_Settings_Page {
|
|||
),
|
||||
);
|
||||
|
||||
$settings = apply_filters(
|
||||
return apply_filters(
|
||||
'woocommerce_' . $this->id . '_settings',
|
||||
$account_settings
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,375 +31,380 @@ class WC_Settings_Advanced extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get own sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
protected function get_own_sections() {
|
||||
return array(
|
||||
'' => __( 'Page setup', 'woocommerce' ),
|
||||
'keys' => __( 'REST API', 'woocommerce' ),
|
||||
'webhooks' => __( 'Webhooks', 'woocommerce' ),
|
||||
'legacy_api' => __( 'Legacy API', 'woocommerce' ),
|
||||
'woocommerce_com' => __( 'WooCommerce.com', 'woocommerce' ),
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array.
|
||||
*
|
||||
* @param string $current_section Current section slug.
|
||||
* Get settings for the default section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
$settings = array();
|
||||
|
||||
if ( '' === $current_section ) {
|
||||
$settings = apply_filters(
|
||||
'woocommerce_settings_pages',
|
||||
protected function get_settings_for_default_section() {
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Page setup', 'woocommerce' ),
|
||||
'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to checkout.', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'advanced_page_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Page setup', 'woocommerce' ),
|
||||
'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to checkout.', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'advanced_page_options',
|
||||
array(
|
||||
'title' => __( 'Cart page', 'woocommerce' ),
|
||||
/* Translators: %s Page contents. */
|
||||
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) ),
|
||||
'id' => 'woocommerce_cart_page_id',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'default' => '',
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'args' => array(
|
||||
'exclude' =>
|
||||
array(
|
||||
wc_get_page_id( 'checkout' ),
|
||||
wc_get_page_id( 'myaccount' ),
|
||||
),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Cart page', 'woocommerce' ),
|
||||
/* Translators: %s Page contents. */
|
||||
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) ),
|
||||
'id' => 'woocommerce_cart_page_id',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'default' => '',
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'args' => array(
|
||||
'exclude' =>
|
||||
array(
|
||||
wc_get_page_id( 'checkout' ),
|
||||
wc_get_page_id( 'myaccount' ),
|
||||
),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
array(
|
||||
'title' => __( 'Checkout page', 'woocommerce' ),
|
||||
/* Translators: %s Page contents. */
|
||||
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) ),
|
||||
'id' => 'woocommerce_checkout_page_id',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'default' => wc_get_page_id( 'checkout' ),
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'args' => array(
|
||||
'exclude' =>
|
||||
array(
|
||||
wc_get_page_id( 'cart' ),
|
||||
wc_get_page_id( 'myaccount' ),
|
||||
),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Checkout page', 'woocommerce' ),
|
||||
/* Translators: %s Page contents. */
|
||||
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) ),
|
||||
'id' => 'woocommerce_checkout_page_id',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'default' => wc_get_page_id( 'checkout' ),
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'args' => array(
|
||||
'exclude' =>
|
||||
array(
|
||||
wc_get_page_id( 'cart' ),
|
||||
wc_get_page_id( 'myaccount' ),
|
||||
),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
array(
|
||||
'title' => __( 'My account page', 'woocommerce' ),
|
||||
/* Translators: %s Page contents. */
|
||||
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) ),
|
||||
'id' => 'woocommerce_myaccount_page_id',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'default' => '',
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'args' => array(
|
||||
'exclude' =>
|
||||
array(
|
||||
wc_get_page_id( 'cart' ),
|
||||
wc_get_page_id( 'checkout' ),
|
||||
),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'My account page', 'woocommerce' ),
|
||||
/* Translators: %s Page contents. */
|
||||
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) ),
|
||||
'id' => 'woocommerce_myaccount_page_id',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'default' => '',
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'args' => array(
|
||||
'exclude' =>
|
||||
array(
|
||||
wc_get_page_id( 'cart' ),
|
||||
wc_get_page_id( 'checkout' ),
|
||||
),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Terms and conditions', 'woocommerce' ),
|
||||
'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_terms_page_id',
|
||||
'default' => '',
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'args' => array( 'exclude' => wc_get_page_id( 'checkout' ) ),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Terms and conditions', 'woocommerce' ),
|
||||
'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_terms_page_id',
|
||||
'default' => '',
|
||||
'class' => 'wc-page-search',
|
||||
'css' => 'min-width:300px;',
|
||||
'type' => 'single_select_page_with_search',
|
||||
'args' => array( 'exclude' => wc_get_page_id( 'checkout' ) ),
|
||||
'desc_tip' => true,
|
||||
'autoload' => false,
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'advanced_page_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'advanced_page_options',
|
||||
),
|
||||
array(
|
||||
'title' => '',
|
||||
'type' => 'title',
|
||||
'id' => 'checkout_process_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => '',
|
||||
'type' => 'title',
|
||||
'id' => 'checkout_process_options',
|
||||
),
|
||||
'force_ssl_checkout' => array(
|
||||
'title' => __( 'Secure checkout', 'woocommerce' ),
|
||||
'desc' => __( 'Force secure checkout', 'woocommerce' ),
|
||||
'id' => 'woocommerce_force_ssl_checkout',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
/* Translators: %s Docs URL. */
|
||||
'desc_tip' => sprintf( __( 'Force SSL (HTTPS) on the checkout pages (<a href="%s" target="_blank">an SSL Certificate is required</a>).', 'woocommerce' ), 'https://docs.woocommerce.com/document/ssl-and-https/#section-3' ),
|
||||
),
|
||||
|
||||
'force_ssl_checkout' => array(
|
||||
'title' => __( 'Secure checkout', 'woocommerce' ),
|
||||
'desc' => __( 'Force secure checkout', 'woocommerce' ),
|
||||
'id' => 'woocommerce_force_ssl_checkout',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
/* Translators: %s Docs URL. */
|
||||
'desc_tip' => sprintf( __( 'Force SSL (HTTPS) on the checkout pages (<a href="%s" target="_blank">an SSL Certificate is required</a>).', 'woocommerce' ), 'https://docs.woocommerce.com/document/ssl-and-https/#section-3' ),
|
||||
),
|
||||
'unforce_ssl_checkout' => array(
|
||||
'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ),
|
||||
'id' => 'woocommerce_unforce_ssl_checkout',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
),
|
||||
|
||||
'unforce_ssl_checkout' => array(
|
||||
'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ),
|
||||
'id' => 'woocommerce_unforce_ssl_checkout',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'checkout_process_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'checkout_process_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Checkout endpoints', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'woocommerce' ),
|
||||
'id' => 'checkout_endpoint_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Checkout endpoints', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'woocommerce' ),
|
||||
'id' => 'checkout_endpoint_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Pay', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "Checkout → Pay" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_checkout_pay_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'order-pay',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Pay', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "Checkout → Pay" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_checkout_pay_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'order-pay',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Order received', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "Checkout → Order received" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_checkout_order_received_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'order-received',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Order received', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "Checkout → Order received" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_checkout_order_received_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'order-received',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Add payment method', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "Checkout → Add payment method" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_add_payment_method_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'add-payment-method',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Add payment method', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "Checkout → Add payment method" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_add_payment_method_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'add-payment-method',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Delete payment method', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the delete payment method page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_delete_payment_method_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'delete-payment-method',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Delete payment method', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the delete payment method page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_delete_payment_method_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'delete-payment-method',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Set default payment method', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the setting a default payment method page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_set_default_payment_method_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'set-default-payment-method',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Set default payment method', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the setting a default payment method page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_set_default_payment_method_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'set-default-payment-method',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'checkout_endpoint_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'checkout_endpoint_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Account endpoints', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions on the accounts pages. They should be unique and can be left blank to disable the endpoint.', 'woocommerce' ),
|
||||
'id' => 'account_endpoint_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Account endpoints', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions on the accounts pages. They should be unique and can be left blank to disable the endpoint.', 'woocommerce' ),
|
||||
'id' => 'account_endpoint_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Orders', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Orders" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_orders_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'orders',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Orders', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Orders" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_orders_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'orders',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'View order', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → View order" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_view_order_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'view-order',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'View order', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → View order" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_view_order_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'view-order',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Downloads', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Downloads" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_downloads_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'downloads',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Downloads', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Downloads" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_downloads_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'downloads',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Edit account', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Edit account" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_edit_account_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'edit-account',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Edit account', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Edit account" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_edit_account_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'edit-account',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Addresses', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Addresses" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_edit_address_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'edit-address',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Addresses', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Addresses" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_edit_address_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'edit-address',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Payment methods', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Payment methods" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_payment_methods_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'payment-methods',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Payment methods', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Payment methods" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_payment_methods_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'payment-methods',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Lost password', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Lost password" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_lost_password_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'lost-password',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Lost password', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the "My account → Lost password" page.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_myaccount_lost_password_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'lost-password',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Logout', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the triggering logout. You can add this to your menus via a custom link: yoursite.com/?customer-logout=true', 'woocommerce' ),
|
||||
'id' => 'woocommerce_logout_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'customer-logout',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Logout', 'woocommerce' ),
|
||||
'desc' => __( 'Endpoint for the triggering logout. You can add this to your menus via a custom link: yoursite.com/?customer-logout=true', 'woocommerce' ),
|
||||
'id' => 'woocommerce_logout_endpoint',
|
||||
'type' => 'text',
|
||||
'default' => 'customer-logout',
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'account_endpoint_options',
|
||||
),
|
||||
)
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'account_endpoint_options',
|
||||
),
|
||||
);
|
||||
|
||||
if ( wc_site_is_https() ) {
|
||||
unset( $settings['unforce_ssl_checkout'], $settings['force_ssl_checkout'] );
|
||||
}
|
||||
} elseif ( 'woocommerce_com' === $current_section ) {
|
||||
$tracking_info_text = sprintf( '<a href="%s" target="_blank">%s</a>', 'https://woocommerce.com/usage-tracking', esc_html__( 'WooCommerce.com Usage Tracking Documentation', 'woocommerce' ) );
|
||||
$settings = apply_filters( 'woocommerce_settings_pages', $settings );
|
||||
|
||||
$settings = apply_filters(
|
||||
'woocommerce_com_integration_settings',
|
||||
array(
|
||||
array(
|
||||
'title' => esc_html__( 'Usage Tracking', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'tracking_options',
|
||||
'desc' => __( 'Gathering usage data allows us to make WooCommerce better — your store will be considered as we evaluate new features, judge the quality of an update, or determine if an improvement makes sense.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Enable tracking', 'woocommerce' ),
|
||||
'desc' => __( 'Allow usage of WooCommerce to be tracked', 'woocommerce' ),
|
||||
/* Translators: %s URL to tracking info screen. */
|
||||
'desc_tip' => sprintf( esc_html__( 'To opt out, leave this box unticked. Your store remains untracked, and no data will be collected. Read about what usage data is tracked at: %s.', 'woocommerce' ), $tracking_info_text ),
|
||||
'id' => 'woocommerce_allow_tracking',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'default' => 'no',
|
||||
'autoload' => false,
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'tracking_options',
|
||||
),
|
||||
array(
|
||||
'title' => esc_html__( 'Marketplace suggestions', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'marketplace_suggestions',
|
||||
'desc' => __( 'We show contextual suggestions for official extensions that may be helpful to your store.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Show Suggestions', 'woocommerce' ),
|
||||
'desc' => __( 'Display suggestions within WooCommerce', 'woocommerce' ),
|
||||
'desc_tip' => esc_html__( 'Leave this box unchecked if you do not want to see suggested extensions.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_show_marketplace_suggestions',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'default' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'marketplace_suggestions',
|
||||
),
|
||||
)
|
||||
);
|
||||
} elseif ( 'legacy_api' === $current_section ) {
|
||||
$settings = apply_filters(
|
||||
'woocommerce_settings_rest_api',
|
||||
array(
|
||||
array(
|
||||
'title' => '',
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'legacy_api_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Legacy API', 'woocommerce' ),
|
||||
'desc' => __( 'Enable the legacy REST API', 'woocommerce' ),
|
||||
'id' => 'woocommerce_api_enabled',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'no',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'legacy_api_options',
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( wc_site_is_https() ) {
|
||||
unset( $settings['unforce_ssl_checkout'], $settings['force_ssl_checkout'] );
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for the WooCommerce.com section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_settings_for_woocommerce_com_section() {
|
||||
$tracking_info_text = sprintf( '<a href="%s" target="_blank">%s</a>', 'https://woocommerce.com/usage-tracking', esc_html__( 'WooCommerce.com Usage Tracking Documentation', 'woocommerce' ) );
|
||||
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
'title' => esc_html__( 'Usage Tracking', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'tracking_options',
|
||||
'desc' => __( 'Gathering usage data allows us to make WooCommerce better — your store will be considered as we evaluate new features, judge the quality of an update, or determine if an improvement makes sense.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Enable tracking', 'woocommerce' ),
|
||||
'desc' => __( 'Allow usage of WooCommerce to be tracked', 'woocommerce' ),
|
||||
/* Translators: %s URL to tracking info screen. */
|
||||
'desc_tip' => sprintf( esc_html__( 'To opt out, leave this box unticked. Your store remains untracked, and no data will be collected. Read about what usage data is tracked at: %s.', 'woocommerce' ), $tracking_info_text ),
|
||||
'id' => 'woocommerce_allow_tracking',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'default' => 'no',
|
||||
'autoload' => false,
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'tracking_options',
|
||||
),
|
||||
array(
|
||||
'title' => esc_html__( 'Marketplace suggestions', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'marketplace_suggestions',
|
||||
'desc' => __( 'We show contextual suggestions for official extensions that may be helpful to your store.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Show Suggestions', 'woocommerce' ),
|
||||
'desc' => __( 'Display suggestions within WooCommerce', 'woocommerce' ),
|
||||
'desc_tip' => esc_html__( 'Leave this box unchecked if you do not want to see suggested extensions.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_show_marketplace_suggestions',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'default' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'marketplace_suggestions',
|
||||
),
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_com_integration_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for the legacy API section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_settings_for_legacy_api_section() {
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
'title' => '',
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'legacy_api_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Legacy API', 'woocommerce' ),
|
||||
'desc' => __( 'Enable the legacy REST API', 'woocommerce' ),
|
||||
'id' => 'woocommerce_api_enabled',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'no',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'legacy_api_options',
|
||||
),
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_settings_rest_api', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -419,12 +424,14 @@ class WC_Settings_Advanced extends WC_Settings_Page {
|
|||
* Notices.
|
||||
*/
|
||||
private function notices() {
|
||||
if ( isset( $_GET['section'] ) && 'webhooks' === $_GET['section'] ) { // WPCS: input var okay, CSRF ok.
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
if ( isset( $_GET['section'] ) && 'webhooks' === $_GET['section'] ) {
|
||||
WC_Admin_Webhooks::notices();
|
||||
}
|
||||
if ( isset( $_GET['section'] ) && 'keys' === $_GET['section'] ) { // WPCS: input var okay, CSRF ok.
|
||||
if ( isset( $_GET['section'] ) && 'keys' === $_GET['section'] ) {
|
||||
WC_Admin_API_Keys::notices();
|
||||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -438,8 +445,7 @@ class WC_Settings_Advanced extends WC_Settings_Page {
|
|||
} elseif ( 'keys' === $current_section ) {
|
||||
WC_Admin_API_Keys::page_output();
|
||||
} else {
|
||||
$settings = $this->get_settings( $current_section );
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
parent::output();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,45 +453,43 @@ class WC_Settings_Advanced extends WC_Settings_Page {
|
|||
* Save settings.
|
||||
*/
|
||||
public function save() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
global $current_section;
|
||||
|
||||
if ( apply_filters( 'woocommerce_rest_api_valid_to_save', ! in_array( $current_section, array( 'keys', 'webhooks' ), true ) ) ) {
|
||||
$settings = $this->get_settings( $current_section );
|
||||
|
||||
// Prevent the T&Cs and checkout page from being set to the same page.
|
||||
if ( isset( $_POST['woocommerce_terms_page_id'], $_POST['woocommerce_checkout_page_id'] ) && $_POST['woocommerce_terms_page_id'] === $_POST['woocommerce_checkout_page_id'] ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( isset( $_POST['woocommerce_terms_page_id'], $_POST['woocommerce_checkout_page_id'] ) && $_POST['woocommerce_terms_page_id'] === $_POST['woocommerce_checkout_page_id'] ) {
|
||||
$_POST['woocommerce_terms_page_id'] = '';
|
||||
}
|
||||
|
||||
// Prevent the Cart, checkout and my account page from being set to the same page.
|
||||
if ( isset( $_POST['woocommerce_cart_page_id'], $_POST['woocommerce_checkout_page_id'], $_POST['woocommerce_myaccount_page_id'] ) ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( $_POST['woocommerce_cart_page_id'] === $_POST['woocommerce_checkout_page_id'] ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( isset( $_POST['woocommerce_cart_page_id'], $_POST['woocommerce_checkout_page_id'], $_POST['woocommerce_myaccount_page_id'] ) ) {
|
||||
if ( $_POST['woocommerce_cart_page_id'] === $_POST['woocommerce_checkout_page_id'] ) {
|
||||
$_POST['woocommerce_checkout_page_id'] = '';
|
||||
}
|
||||
if ( $_POST['woocommerce_cart_page_id'] === $_POST['woocommerce_myaccount_page_id'] ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( $_POST['woocommerce_cart_page_id'] === $_POST['woocommerce_myaccount_page_id'] ) {
|
||||
$_POST['woocommerce_myaccount_page_id'] = '';
|
||||
}
|
||||
if ( $_POST['woocommerce_checkout_page_id'] === $_POST['woocommerce_myaccount_page_id'] ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( $_POST['woocommerce_checkout_page_id'] === $_POST['woocommerce_myaccount_page_id'] ) {
|
||||
$_POST['woocommerce_myaccount_page_id'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
WC_Admin_Settings::save_fields( $settings );
|
||||
|
||||
if ( $current_section ) {
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
||||
}
|
||||
$this->save_settings_for_current_section();
|
||||
$this->do_update_options_action();
|
||||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound, Generic.Commenting.Todo.CommentFound
|
||||
/**
|
||||
* WC_Settings_Rest_API class.
|
||||
*
|
||||
* @deprecated 3.4 in favour of WC_Settings_Advanced.
|
||||
* @todo remove in 4.0.
|
||||
*/
|
||||
class WC_Settings_Rest_API extends WC_Settings_Advanced {
|
||||
} // @codingStandardsIgnoreLine.
|
||||
}
|
||||
|
||||
return new WC_Settings_Advanced();
|
||||
// phpcs:enable
|
||||
|
|
|
@ -29,15 +29,14 @@ class WC_Settings_Emails extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get own sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
protected function get_own_sections() {
|
||||
return array(
|
||||
'' => __( 'Email options', 'woocommerce' ),
|
||||
);
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +44,7 @@ class WC_Settings_Emails extends WC_Settings_Page {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
protected function get_settings_for_default_section() {
|
||||
$desc_help_text = sprintf(
|
||||
/* translators: %1$s: Link to WP Mail Logging plugin, %2$s: Link to Email FAQ support page. */
|
||||
__( 'To ensure your store’s notifications arrive in your and your customers’ inboxes, we recommend connecting your email address to your domain and setting up a dedicated SMTP server. If something doesn’t seem to be sending correctly, install the <a href="%1$s">WP Mail Logging Plugin</a> or check the <a href="%2$s">Email FAQ page</a>.', 'woocommerce' ),
|
||||
|
@ -221,7 +220,7 @@ class WC_Settings_Emails extends WC_Settings_Page {
|
|||
)
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
|
||||
return apply_filters( 'woocommerce_email_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,14 +236,23 @@ class WC_Settings_Emails extends WC_Settings_Page {
|
|||
if ( $current_section ) {
|
||||
foreach ( $email_templates as $email_key => $email ) {
|
||||
if ( strtolower( $email_key ) === $current_section ) {
|
||||
$email->admin_options();
|
||||
$this->run_email_admin_options( $email );
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
|
||||
parent::output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the 'admin_options' method on a given email.
|
||||
* This method exists to easy unit testing.
|
||||
*
|
||||
* @param object $email The email object to run the method on.
|
||||
*/
|
||||
protected function run_email_admin_options( $email ) {
|
||||
$email->admin_options();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,19 +262,20 @@ class WC_Settings_Emails extends WC_Settings_Page {
|
|||
global $current_section;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
WC_Admin_Settings::save_fields( $this->get_settings() );
|
||||
|
||||
$this->save_settings_for_current_section();
|
||||
$this->do_update_options_action();
|
||||
} else {
|
||||
$wc_emails = WC_Emails::instance();
|
||||
|
||||
if ( in_array( $current_section, array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ), true ) ) {
|
||||
foreach ( $wc_emails->get_emails() as $email_id => $email ) {
|
||||
if ( sanitize_title( $email_id ) === $current_section ) {
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $email->id );
|
||||
$this->do_update_options_action( $email->id );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
||||
$this->save_settings_for_current_section();
|
||||
$this->do_update_options_action();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ class WC_Settings_General extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get settings array.
|
||||
* Get settings or the default section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
protected function get_settings_for_default_section() {
|
||||
|
||||
$currency_code_options = get_woocommerce_currencies();
|
||||
|
||||
|
@ -39,8 +39,7 @@ class WC_Settings_General extends WC_Settings_Page {
|
|||
$currency_code_options[ $code ] = $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')';
|
||||
}
|
||||
|
||||
$settings = apply_filters(
|
||||
'woocommerce_general_settings',
|
||||
$settings =
|
||||
array(
|
||||
|
||||
array(
|
||||
|
@ -290,11 +289,9 @@ class WC_Settings_General extends WC_Settings_Page {
|
|||
'type' => 'sectionend',
|
||||
'id' => 'pricing_options',
|
||||
),
|
||||
);
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
|
||||
return apply_filters( 'woocommerce_general_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -310,24 +307,6 @@ class WC_Settings_General extends WC_Settings_Page {
|
|||
<input name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '" type="text" value="' . esc_attr( $value ) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr( $id ) . '" class="colorpickdiv"></div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings.
|
||||
*/
|
||||
public function output() {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings.
|
||||
*/
|
||||
public function save() {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
WC_Admin_Settings::save_fields( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
return new WC_Settings_General();
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
/**
|
||||
* WooCommerce Integration Settings
|
||||
*
|
||||
* @package WooCommerce\Admin
|
||||
* @version 2.1.0
|
||||
* @package WooCommerce\Admin
|
||||
* @version 2.1.0
|
||||
*/
|
||||
|
||||
use Automattic\Jetpack\Constants;
|
||||
|
@ -30,17 +30,17 @@ if ( ! class_exists( 'WC_Settings_Integrations', false ) ) :
|
|||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get own sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
protected function get_own_sections() {
|
||||
global $current_section;
|
||||
|
||||
$sections = array();
|
||||
|
||||
if ( ! Constants::is_defined( 'WC_INSTALLING' ) ) {
|
||||
$integrations = WC()->integrations->get_integrations();
|
||||
if ( ! $this->wc_is_installing() ) {
|
||||
$integrations = $this->get_integrations();
|
||||
|
||||
if ( ! $current_section && ! empty( $integrations ) ) {
|
||||
$current_section = current( $integrations )->id;
|
||||
|
@ -54,7 +54,27 @@ if ( ! class_exists( 'WC_Settings_Integrations', false ) ) :
|
|||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is WC_INSTALLING constant defined?
|
||||
* This method exists to ease unit testing.
|
||||
*
|
||||
* @return bool True is the WC_INSTALLING constant is defined.
|
||||
*/
|
||||
protected function wc_is_installing() {
|
||||
return Constants::is_defined( 'WC_INSTALLING' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently available integrations.
|
||||
* This method exists to ease unit testing.
|
||||
*
|
||||
* @return array Currently available integrations.
|
||||
*/
|
||||
protected function get_integrations() {
|
||||
return WC()->integrations->get_integrations();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +83,7 @@ if ( ! class_exists( 'WC_Settings_Integrations', false ) ) :
|
|||
public function output() {
|
||||
global $current_section;
|
||||
|
||||
$integrations = WC()->integrations->get_integrations();
|
||||
$integrations = $this->get_integrations();
|
||||
|
||||
if ( isset( $integrations[ $current_section ] ) ) {
|
||||
$integrations[ $current_section ]->admin_options();
|
||||
|
|
|
@ -64,7 +64,7 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) :
|
|||
/**
|
||||
* Add this page to settings.
|
||||
*
|
||||
* @param array $pages The pages array to add this page to.
|
||||
* @param array $pages The setings array where we'll add ourselves.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -75,21 +75,102 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) :
|
|||
}
|
||||
|
||||
/**
|
||||
* Get settings array.
|
||||
* Get settings array for the default section.
|
||||
*
|
||||
* @return array
|
||||
* External settings classes (registered via 'woocommerce_get_settings_pages' filter)
|
||||
* might have redefined this method as "get_settings($section_id='')", thus we need
|
||||
* to use this method internally instead of 'get_settings_for_section' to register settings
|
||||
* and render settings pages.
|
||||
*
|
||||
* *But* we can't just redefine the method as "get_settings($section_id='')" here, since this
|
||||
* will break on PHP 8 if any external setting class have it as 'get_settings()'.
|
||||
*
|
||||
* Thus we leave the method signature as is and use 'func_get_arg' to get the setting id
|
||||
* if it's supplied, and we use this method internally; but it's deprecated and should
|
||||
* otherwise never be used.
|
||||
*
|
||||
* @deprecated 5.4.0 Use 'get_settings_for_section' (passing an empty string for default section)
|
||||
*
|
||||
* @return array Settings array, each item being an associative array representing a setting.
|
||||
*/
|
||||
public function get_settings() {
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, array() );
|
||||
$section_id = 0 === func_num_args() ? '' : func_get_arg( 0 );
|
||||
return $this->get_settings_for_section( $section_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get settings array.
|
||||
*
|
||||
* The strategy for getting the settings is as follows:
|
||||
*
|
||||
* - If a method named 'get_settings_for_{section_id}_section' exists in the class
|
||||
* it will be invoked (for the default '' section, the method name is 'get_settings_for_default_section').
|
||||
* Derived classes can implement these methods as required.
|
||||
*
|
||||
* - Otherwise, 'get_settings_for_section_core' will be invoked. Derived classes can override it
|
||||
* as an alternative to implementing 'get_settings_for_{section_id}_section' methods.
|
||||
*
|
||||
* @param string $section_id The id of the section to return settings for, an empty string for the default section.
|
||||
*
|
||||
* @return array Settings array, each item being an associative array representing a setting.
|
||||
*/
|
||||
final public function get_settings_for_section( $section_id ) {
|
||||
if ( '' === $section_id ) {
|
||||
$method_name = 'get_settings_for_default_section';
|
||||
} else {
|
||||
$method_name = "get_settings_for_{$section_id}_section";
|
||||
}
|
||||
|
||||
if ( method_exists( $this, $method_name ) ) {
|
||||
$settings = $this->$method_name();
|
||||
} else {
|
||||
$settings = $this->get_settings_for_section_core( $section_id );
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $section_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a given section.
|
||||
* This method is invoked from 'get_settings_for_section' when no 'get_settings_for_{current_section}_section'
|
||||
* method exists in the class.
|
||||
*
|
||||
* When overriding, note that the 'woocommerce_get_settings_' filter must NOT be triggered,
|
||||
* as this is already done by 'get_settings_for_section'.
|
||||
*
|
||||
* @param string $section_id The section name to get the settings for.
|
||||
*
|
||||
* @return array Settings array, each item being an associative array representing a setting.
|
||||
*/
|
||||
protected function get_settings_for_section_core( $section_id ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sections for this page, both the own ones and the ones defined via filters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, array() );
|
||||
$sections = $this->get_own_sections();
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get own sections for this page.
|
||||
* Derived classes should override this method if they define sections.
|
||||
* There should always be one default section with an empty string as identifier.
|
||||
*
|
||||
* Example:
|
||||
* return array(
|
||||
* '' => __( 'General', 'woocommerce' ),
|
||||
* 'foobars' => __( 'Foos & Bars', 'woocommerce' ),
|
||||
* );
|
||||
*
|
||||
* @return array An associative array where keys are section identifiers and the values are translated section names.
|
||||
*/
|
||||
protected function get_own_sections() {
|
||||
return array( '' => __( 'General', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,33 +190,63 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) :
|
|||
$array_keys = array_keys( $sections );
|
||||
|
||||
foreach ( $sections as $id => $label ) {
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) . '" class="' . ( $current_section === $id ? 'current' : '' ) . '">' . esc_html( $label ) . '</a> ' . ( end( $array_keys ) === $id ? '' : '|' ) . ' </li>';
|
||||
$url = admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) );
|
||||
$class = ( $current_section === $id ? 'current' : '' );
|
||||
$separator = ( end( $array_keys ) === $id ? '' : '|' );
|
||||
$text = esc_html( $label );
|
||||
echo "<li><a href='$url' class='$class'>$text</a> $separator </li>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
echo '</ul><br class="clear" />';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings.
|
||||
* Output the HTML for the settings.
|
||||
*/
|
||||
public function output() {
|
||||
$settings = $this->get_settings();
|
||||
global $current_section;
|
||||
|
||||
// We can't use "get_settings_for_section" here
|
||||
// for compatibility with derived classes overriding "get_settings".
|
||||
$settings = $this->get_settings( $current_section );
|
||||
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings.
|
||||
* Save settings and trigger the 'woocommerce_update_options_'.id action.
|
||||
*/
|
||||
public function save() {
|
||||
$this->save_settings_for_current_section();
|
||||
$this->do_update_options_action();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings for current section.
|
||||
*/
|
||||
protected function save_settings_for_current_section() {
|
||||
global $current_section;
|
||||
|
||||
$settings = $this->get_settings();
|
||||
// We can't use "get_settings_for_section" here
|
||||
// for compatibility with derived classes overriding "get_settings".
|
||||
$settings = $this->get_settings( $current_section );
|
||||
WC_Admin_Settings::save_fields( $settings );
|
||||
}
|
||||
|
||||
if ( $current_section ) {
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
||||
/**
|
||||
* Trigger the 'woocommerce_update_options_'.id action.
|
||||
*
|
||||
* @param string $section_id Section to trigger the action for, or null for current section.
|
||||
*/
|
||||
protected function do_update_options_action( $section_id = null ) {
|
||||
global $current_section;
|
||||
|
||||
if ( is_null( $section_id ) ) {
|
||||
$section_id = $current_section;
|
||||
}
|
||||
|
||||
if ( $section_id ) {
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $section_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,54 +28,47 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get own sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
protected function get_own_sections() {
|
||||
return array(
|
||||
'' => __( 'Payment methods', 'woocommerce' ),
|
||||
);
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array.
|
||||
*
|
||||
* @param string $current_section Section being shown.
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
$settings = array();
|
||||
|
||||
if ( '' === $current_section ) {
|
||||
$settings = apply_filters(
|
||||
'woocommerce_payment_gateways_settings',
|
||||
protected function get_settings_for_default_section() {
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Payment methods', 'woocommerce' ),
|
||||
'desc' => __( 'Installed payment methods are listed below and can be sorted to control their display order on the frontend.', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'payment_gateways_options',
|
||||
),
|
||||
array(
|
||||
'type' => 'payment_gateways',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'payment_gateways_options',
|
||||
),
|
||||
)
|
||||
'title' => __( 'Payment methods', 'woocommerce' ),
|
||||
'desc' => __( 'Installed payment methods are listed below and can be sorted to control their display order on the frontend.', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'payment_gateways_options',
|
||||
),
|
||||
array(
|
||||
'type' => 'payment_gateways',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'payment_gateways_options',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
||||
return apply_filters( 'woocommerce_payment_gateways_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings.
|
||||
*/
|
||||
public function output() {
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
global $current_section;
|
||||
|
||||
// Load gateways so we can show any global options they may have.
|
||||
|
@ -84,20 +77,31 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
|
|||
if ( $current_section ) {
|
||||
foreach ( $payment_gateways as $gateway ) {
|
||||
if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ), true ) ) {
|
||||
if ( isset( $_GET['toggle_enabled'] ) ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( isset( $_GET['toggle_enabled'] ) ) {
|
||||
$enabled = $gateway->get_option( 'enabled' );
|
||||
|
||||
if ( $enabled ) {
|
||||
$gateway->settings['enabled'] = wc_string_to_bool( $enabled ) ? 'no' : 'yes';
|
||||
}
|
||||
}
|
||||
$gateway->admin_options();
|
||||
$this->run_gateway_admin_options( $gateway );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$settings = $this->get_settings( $current_section );
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
|
||||
parent::output();
|
||||
//phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the 'admin_options' method on a given gateway.
|
||||
* This method exists to easy unit testing.
|
||||
*
|
||||
* @param object $gateway The gateway object to run the method on.
|
||||
*/
|
||||
protected function run_gateway_admin_options( $gateway ) {
|
||||
$gateway->admin_options();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,8 +217,7 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
|
|||
|
||||
$wc_payment_gateways = WC_Payment_Gateways::instance();
|
||||
|
||||
// Save settings fields based on section.
|
||||
WC_Admin_Settings::save_fields( $this->get_settings( $current_section ) );
|
||||
$this->save_settings_for_current_section();
|
||||
|
||||
if ( ! $current_section ) {
|
||||
// If section is empty, we're on the main settings page. This makes sure 'gateway ordering' is saved.
|
||||
|
@ -229,7 +232,7 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
|
|||
}
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
||||
$this->do_update_options_action();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,435 +30,418 @@ class WC_Settings_Products extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get own sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
$sections = array(
|
||||
protected function get_own_sections() {
|
||||
return array(
|
||||
'' => __( 'General', 'woocommerce' ),
|
||||
'inventory' => __( 'Inventory', 'woocommerce' ),
|
||||
'downloadable' => __( 'Downloadable products', 'woocommerce' ),
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the settings.
|
||||
* Get settings for the detault section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function output() {
|
||||
global $current_section;
|
||||
protected function get_settings_for_default_section() {
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Shop pages', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'catalog_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Shop page', 'woocommerce' ),
|
||||
/* translators: %s: URL to settings. */
|
||||
'desc' => sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
|
||||
'id' => 'woocommerce_shop_page_id',
|
||||
'type' => 'single_select_page',
|
||||
'default' => '',
|
||||
'class' => 'wc-enhanced-select-nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
|
||||
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
|
||||
'id' => 'woocommerce_cart_redirect_after_add',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
),
|
||||
array(
|
||||
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_ajax_add_to_cart',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Placeholder image', 'woocommerce' ),
|
||||
'id' => 'woocommerce_placeholder_image',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'class' => '',
|
||||
'css' => '',
|
||||
'placeholder' => __( 'Enter attachment ID or URL to an image', 'woocommerce' ),
|
||||
'desc_tip' => __( 'This is the attachment ID, or image URL, used for placeholder images in the product catalog. Products with no image will use this.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'catalog_options',
|
||||
),
|
||||
|
||||
$settings = $this->get_settings( $current_section );
|
||||
array(
|
||||
'title' => __( 'Measurements', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'product_measurement_options',
|
||||
),
|
||||
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
array(
|
||||
'title' => __( 'Weight unit', 'woocommerce' ),
|
||||
'desc' => __( 'This controls what unit you will define weights in.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_weight_unit',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'kg',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'kg' => __( 'kg', 'woocommerce' ),
|
||||
'g' => __( 'g', 'woocommerce' ),
|
||||
'lbs' => __( 'lbs', 'woocommerce' ),
|
||||
'oz' => __( 'oz', 'woocommerce' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Dimensions unit', 'woocommerce' ),
|
||||
'desc' => __( 'This controls what unit you will define lengths in.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_dimension_unit',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'cm',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'm' => __( 'm', 'woocommerce' ),
|
||||
'cm' => __( 'cm', 'woocommerce' ),
|
||||
'mm' => __( 'mm', 'woocommerce' ),
|
||||
'in' => __( 'in', 'woocommerce' ),
|
||||
'yd' => __( 'yd', 'woocommerce' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'product_measurement_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Reviews', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'product_rating_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Enable reviews', 'woocommerce' ),
|
||||
'desc' => __( 'Enable product reviews', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_reviews',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
|
||||
'id' => 'woocommerce_review_rating_verification_label',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
|
||||
'id' => 'woocommerce_review_rating_verification_required',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Product ratings', 'woocommerce' ),
|
||||
'desc' => __( 'Enable star rating on reviews', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_review_rating',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Star ratings should be required, not optional', 'woocommerce' ),
|
||||
'id' => 'woocommerce_review_rating_required',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'product_rating_options',
|
||||
),
|
||||
);
|
||||
|
||||
$settings = apply_filters( 'woocommerce_products_general_settings', $settings );
|
||||
return apply_filters( 'woocommerce_product_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings.
|
||||
* Get settings for the inventory section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_settings_for_inventory_section() {
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Inventory', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'product_inventory_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Manage stock', 'woocommerce' ),
|
||||
'desc' => __( 'Enable stock management', 'woocommerce' ),
|
||||
'id' => 'woocommerce_manage_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Hold stock (minutes)', 'woocommerce' ),
|
||||
'desc' => __( 'Hold stock (for unpaid orders) for x minutes. When this limit is reached, the pending order will be cancelled. Leave blank to disable.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_hold_stock_minutes',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
),
|
||||
'css' => 'width: 80px;',
|
||||
'default' => '60',
|
||||
'autoload' => false,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Notifications', 'woocommerce' ),
|
||||
'desc' => __( 'Enable low stock notifications', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_low_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Enable out of stock notifications', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_no_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Notification recipient(s)', 'woocommerce' ),
|
||||
'desc' => __( 'Enter recipients (comma separated) that will receive this notification.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_stock_email_recipient',
|
||||
'type' => 'text',
|
||||
'default' => get_option( 'admin_email' ),
|
||||
'css' => 'width: 250px;',
|
||||
'autoload' => false,
|
||||
'desc_tip' => true,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Low stock threshold', 'woocommerce' ),
|
||||
'desc' => __( 'When product stock reaches this amount you will be notified via email.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_low_stock_amount',
|
||||
'css' => 'width:50px;',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
),
|
||||
'default' => '2',
|
||||
'autoload' => false,
|
||||
'desc_tip' => true,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Out of stock threshold', 'woocommerce' ),
|
||||
'desc' => __( 'When product stock reaches this amount the stock status will change to "out of stock" and you will be notified via email. This setting does not affect existing "in stock" products.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_no_stock_amount',
|
||||
'css' => 'width:50px;',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
),
|
||||
'default' => '0',
|
||||
'desc_tip' => true,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Out of stock visibility', 'woocommerce' ),
|
||||
'desc' => __( 'Hide out of stock items from the catalog', 'woocommerce' ),
|
||||
'id' => 'woocommerce_hide_out_of_stock_items',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Stock display format', 'woocommerce' ),
|
||||
'desc' => __( 'This controls how stock quantities are displayed on the frontend.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_stock_format',
|
||||
'css' => 'min-width:150px;',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'default' => '',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'Always show quantity remaining in stock e.g. "12 in stock"', 'woocommerce' ),
|
||||
'low_amount' => __( 'Only show quantity remaining in stock when low e.g. "Only 2 left in stock"', 'woocommerce' ),
|
||||
'no_amount' => __( 'Never show quantity remaining in stock', 'woocommerce' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'product_inventory_options',
|
||||
),
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_inventory_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for the downloadable section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_settings_for_downloadable_section() {
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Downloadable products', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'digital_download_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'File download method', 'woocommerce' ),
|
||||
'desc_tip' => sprintf(
|
||||
/* translators: 1: X-Accel-Redirect 2: X-Sendfile 3: mod_xsendfile */
|
||||
__( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, %1$s / %2$s can be used to serve downloads instead (server requires %3$s).', 'woocommerce' ),
|
||||
'<code>X-Accel-Redirect</code>',
|
||||
'<code>X-Sendfile</code>',
|
||||
'<code>mod_xsendfile</code>'
|
||||
),
|
||||
'id' => 'woocommerce_file_download_method',
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'force',
|
||||
'desc' => sprintf(
|
||||
// translators: Link to WooCommerce Docs.
|
||||
__( "If you are using X-Accel-Redirect download method along with NGINX server, make sure that you have applied settings as described in <a href='%s'>Digital/Downloadable Product Handling</a> guide.", 'woocommerce' ),
|
||||
'https://docs.woocommerce.com/document/digital-downloadable-product-handling#nginx-setting'
|
||||
),
|
||||
'options' => array(
|
||||
'force' => __( 'Force downloads', 'woocommerce' ),
|
||||
'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'woocommerce' ),
|
||||
'redirect' => apply_filters( 'woocommerce_redirect_only_method_is_secure', false ) ? __( 'Redirect only', 'woocommerce' ) : __( 'Redirect only (Insecure)', 'woocommerce' ),
|
||||
),
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Access restriction', 'woocommerce' ),
|
||||
'desc' => __( 'Downloads require login', 'woocommerce' ),
|
||||
'id' => 'woocommerce_downloads_require_login',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'no',
|
||||
'desc_tip' => __( 'This setting does not apply to guest purchases.', 'woocommerce' ),
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Grant access to downloadable products after payment', 'woocommerce' ),
|
||||
'id' => 'woocommerce_downloads_grant_access_after_payment',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'yes',
|
||||
'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'woocommerce' ),
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Filename', 'woocommerce' ),
|
||||
'desc' => __( 'Append a unique string to filename for security', 'woocommerce' ),
|
||||
'id' => 'woocommerce_downloads_add_hash_to_filename',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'yes',
|
||||
'desc_tip' => sprintf(
|
||||
// translators: Link to WooCommerce Docs.
|
||||
__( "Not required if your download directory is protected. <a href='%s'>See this guide</a> for more details. Files already uploaded will not be affected.", 'woocommerce' ),
|
||||
'https://docs.woocommerce.com/document/digital-downloadable-product-handling#unique-string'
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'digital_download_options',
|
||||
),
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_downloadable_products_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings and trigger the 'woocommerce_update_options_'.id action.
|
||||
*/
|
||||
public function save() {
|
||||
global $current_section;
|
||||
|
||||
$settings = $this->get_settings( $current_section );
|
||||
WC_Admin_Settings::save_fields( $settings );
|
||||
$this->save_settings_for_current_section();
|
||||
|
||||
/*
|
||||
* Product->Inventory has a setting `Out of stock visibility`.
|
||||
* Because of this, we need to recount the terms to keep them in-sync.
|
||||
*/
|
||||
wc_recount_all_terms();
|
||||
WC()->call_function( 'wc_recount_all_terms' );
|
||||
|
||||
if ( $current_section ) {
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array.
|
||||
*
|
||||
* @param string $current_section Current section name.
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
if ( 'inventory' === $current_section ) {
|
||||
$settings = apply_filters(
|
||||
'woocommerce_inventory_settings',
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Inventory', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'product_inventory_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Manage stock', 'woocommerce' ),
|
||||
'desc' => __( 'Enable stock management', 'woocommerce' ),
|
||||
'id' => 'woocommerce_manage_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Hold stock (minutes)', 'woocommerce' ),
|
||||
'desc' => __( 'Hold stock (for unpaid orders) for x minutes. When this limit is reached, the pending order will be cancelled. Leave blank to disable.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_hold_stock_minutes',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
),
|
||||
'css' => 'width: 80px;',
|
||||
'default' => '60',
|
||||
'autoload' => false,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Notifications', 'woocommerce' ),
|
||||
'desc' => __( 'Enable low stock notifications', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_low_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Enable out of stock notifications', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_no_stock',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Notification recipient(s)', 'woocommerce' ),
|
||||
'desc' => __( 'Enter recipients (comma separated) that will receive this notification.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_stock_email_recipient',
|
||||
'type' => 'text',
|
||||
'default' => get_option( 'admin_email' ),
|
||||
'css' => 'width: 250px;',
|
||||
'autoload' => false,
|
||||
'desc_tip' => true,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Low stock threshold', 'woocommerce' ),
|
||||
'desc' => __( 'When product stock reaches this amount you will be notified via email.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_low_stock_amount',
|
||||
'css' => 'width:50px;',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
),
|
||||
'default' => '2',
|
||||
'autoload' => false,
|
||||
'desc_tip' => true,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Out of stock threshold', 'woocommerce' ),
|
||||
'desc' => __( 'When product stock reaches this amount the stock status will change to "out of stock" and you will be notified via email. This setting does not affect existing "in stock" products.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_notify_no_stock_amount',
|
||||
'css' => 'width:50px;',
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
),
|
||||
'default' => '0',
|
||||
'desc_tip' => true,
|
||||
'class' => 'manage_stock_field',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Out of stock visibility', 'woocommerce' ),
|
||||
'desc' => __( 'Hide out of stock items from the catalog', 'woocommerce' ),
|
||||
'id' => 'woocommerce_hide_out_of_stock_items',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Stock display format', 'woocommerce' ),
|
||||
'desc' => __( 'This controls how stock quantities are displayed on the frontend.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_stock_format',
|
||||
'css' => 'min-width:150px;',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'default' => '',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => __( 'Always show quantity remaining in stock e.g. "12 in stock"', 'woocommerce' ),
|
||||
'low_amount' => __( 'Only show quantity remaining in stock when low e.g. "Only 2 left in stock"', 'woocommerce' ),
|
||||
'no_amount' => __( 'Never show quantity remaining in stock', 'woocommerce' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'product_inventory_options',
|
||||
),
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
} elseif ( 'downloadable' === $current_section ) {
|
||||
$settings = apply_filters(
|
||||
'woocommerce_downloadable_products_settings',
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Downloadable products', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'digital_download_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'File download method', 'woocommerce' ),
|
||||
'desc_tip' => sprintf(
|
||||
/* translators: 1: X-Accel-Redirect 2: X-Sendfile 3: mod_xsendfile */
|
||||
__( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, %1$s / %2$s can be used to serve downloads instead (server requires %3$s).', 'woocommerce' ),
|
||||
'<code>X-Accel-Redirect</code>',
|
||||
'<code>X-Sendfile</code>',
|
||||
'<code>mod_xsendfile</code>'
|
||||
),
|
||||
'id' => 'woocommerce_file_download_method',
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'force',
|
||||
'desc' => sprintf(
|
||||
// translators: Link to WooCommerce Docs.
|
||||
__( "If you are using X-Accel-Redirect download method along with NGINX server, make sure that you have applied settings as described in <a href='%s'>Digital/Downloadable Product Handling</a> guide.", 'woocommerce' ),
|
||||
'https://docs.woocommerce.com/document/digital-downloadable-product-handling#nginx-setting'
|
||||
),
|
||||
'options' => array(
|
||||
'force' => __( 'Force downloads', 'woocommerce' ),
|
||||
'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'woocommerce' ),
|
||||
'redirect' => apply_filters( 'woocommerce_redirect_only_method_is_secure', false ) ? __( 'Redirect only', 'woocommerce' ) : __( 'Redirect only (Insecure)', 'woocommerce' ),
|
||||
),
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Access restriction', 'woocommerce' ),
|
||||
'desc' => __( 'Downloads require login', 'woocommerce' ),
|
||||
'id' => 'woocommerce_downloads_require_login',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'no',
|
||||
'desc_tip' => __( 'This setting does not apply to guest purchases.', 'woocommerce' ),
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Grant access to downloadable products after payment', 'woocommerce' ),
|
||||
'id' => 'woocommerce_downloads_grant_access_after_payment',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'yes',
|
||||
'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'woocommerce' ),
|
||||
'checkboxgroup' => 'end',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Filename', 'woocommerce' ),
|
||||
'desc' => __( 'Append a unique string to filename for security', 'woocommerce' ),
|
||||
'id' => 'woocommerce_downloads_add_hash_to_filename',
|
||||
'type' => 'checkbox',
|
||||
'default' => 'yes',
|
||||
'desc_tip' => sprintf(
|
||||
// translators: Link to WooCommerce Docs.
|
||||
__( "Not required if your download directory is protected. <a href='%s'>See this guide</a> for more details. Files already uploaded will not be affected.", 'woocommerce' ),
|
||||
'https://docs.woocommerce.com/document/digital-downloadable-product-handling#unique-string'
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'digital_download_options',
|
||||
),
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
$settings = apply_filters(
|
||||
'woocommerce_product_settings',
|
||||
apply_filters(
|
||||
'woocommerce_products_general_settings',
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Shop pages', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'catalog_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Shop page', 'woocommerce' ),
|
||||
/* translators: %s: URL to settings. */
|
||||
'desc' => sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
|
||||
'id' => 'woocommerce_shop_page_id',
|
||||
'type' => 'single_select_page',
|
||||
'default' => '',
|
||||
'args' => array( 'post_status' => 'publish,private' ),
|
||||
'class' => 'wc-enhanced-select-nostd',
|
||||
'css' => 'min-width:300px;',
|
||||
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
|
||||
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
|
||||
'id' => 'woocommerce_cart_redirect_after_add',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
),
|
||||
array(
|
||||
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_ajax_add_to_cart',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Placeholder image', 'woocommerce' ),
|
||||
'id' => 'woocommerce_placeholder_image',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'class' => '',
|
||||
'css' => '',
|
||||
'placeholder' => __( 'Enter attachment ID or URL to an image', 'woocommerce' ),
|
||||
'desc_tip' => __( 'This is the attachment ID, or image URL, used for placeholder images in the product catalog. Products with no image will use this.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'catalog_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Measurements', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'product_measurement_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Weight unit', 'woocommerce' ),
|
||||
'desc' => __( 'This controls what unit you will define weights in.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_weight_unit',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'kg',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'kg' => __( 'kg', 'woocommerce' ),
|
||||
'g' => __( 'g', 'woocommerce' ),
|
||||
'lbs' => __( 'lbs', 'woocommerce' ),
|
||||
'oz' => __( 'oz', 'woocommerce' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Dimensions unit', 'woocommerce' ),
|
||||
'desc' => __( 'This controls what unit you will define lengths in.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_dimension_unit',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'css' => 'min-width:300px;',
|
||||
'default' => 'cm',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'm' => __( 'm', 'woocommerce' ),
|
||||
'cm' => __( 'cm', 'woocommerce' ),
|
||||
'mm' => __( 'mm', 'woocommerce' ),
|
||||
'in' => __( 'in', 'woocommerce' ),
|
||||
'yd' => __( 'yd', 'woocommerce' ),
|
||||
),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'product_measurement_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Reviews', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => 'product_rating_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Enable reviews', 'woocommerce' ),
|
||||
'desc' => __( 'Enable product reviews', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_reviews',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
|
||||
'id' => 'woocommerce_review_rating_verification_label',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
|
||||
'id' => 'woocommerce_review_rating_verification_required',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Product ratings', 'woocommerce' ),
|
||||
'desc' => __( 'Enable star rating on reviews', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_review_rating',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Star ratings should be required, not optional', 'woocommerce' ),
|
||||
'id' => 'woocommerce_review_rating_required',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'product_rating_options',
|
||||
),
|
||||
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
||||
$this->do_update_options_action();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,20 +40,20 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get own sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
protected function get_own_sections() {
|
||||
$sections = array(
|
||||
'' => __( 'Shipping zones', 'woocommerce' ),
|
||||
'options' => __( 'Shipping options', 'woocommerce' ),
|
||||
'classes' => __( 'Shipping classes', 'woocommerce' ),
|
||||
);
|
||||
|
||||
if ( ! Constants::is_defined( 'WC_INSTALLING' ) ) {
|
||||
if ( ! $this->wc_is_installing() ) {
|
||||
// Load shipping methods so we can show any global options they may have.
|
||||
$shipping_methods = WC()->shipping()->load_shipping_methods();
|
||||
$shipping_methods = $this->get_shipping_methods();
|
||||
|
||||
foreach ( $shipping_methods as $method ) {
|
||||
if ( ! $method->has_settings() ) {
|
||||
|
@ -64,81 +64,105 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array.
|
||||
* Is WC_INSTALLING constant defined?
|
||||
* This method exists to ease unit testing.
|
||||
*
|
||||
* @return bool True is the WC_INSTALLING constant is defined.
|
||||
*/
|
||||
protected function wc_is_installing() {
|
||||
return Constants::is_defined( 'WC_INSTALLING' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently available shipping methods.
|
||||
* This method exists to ease unit testing.
|
||||
*
|
||||
* @return array Currently available shipping methods.
|
||||
*/
|
||||
protected function get_shipping_methods() {
|
||||
return WC()->shipping()->get_shipping_methods();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings for the default section.
|
||||
*
|
||||
* The original implementation of 'get_settings' was returning the settings for the "Options" section
|
||||
* when the supplied value for $current_section was ''.
|
||||
*
|
||||
* @param string $current_section Current section.
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
$settings = array();
|
||||
protected function get_settings_for_default_section() {
|
||||
return $this->get_settings_for_options_section();
|
||||
}
|
||||
|
||||
if ( '' === $current_section ) {
|
||||
$settings = apply_filters(
|
||||
'woocommerce_shipping_settings',
|
||||
/**
|
||||
* Get settings for the options section.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_settings_for_options_section() {
|
||||
$settings =
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Shipping options', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'shipping_options',
|
||||
),
|
||||
'title' => __( 'Shipping options', 'woocommerce' ),
|
||||
'type' => 'title',
|
||||
'id' => 'shipping_options',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Calculations', 'woocommerce' ),
|
||||
'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_shipping_calc',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Calculations', 'woocommerce' ),
|
||||
'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ),
|
||||
'id' => 'woocommerce_enable_shipping_calc',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'start',
|
||||
'autoload' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ),
|
||||
'id' => 'woocommerce_shipping_cost_requires_address',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
),
|
||||
array(
|
||||
'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ),
|
||||
'id' => 'woocommerce_shipping_cost_requires_address',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Shipping destination', 'woocommerce' ),
|
||||
'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_ship_to_destination',
|
||||
'default' => 'billing',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'shipping' => __( 'Default to customer shipping address', 'woocommerce' ),
|
||||
'billing' => __( 'Default to customer billing address', 'woocommerce' ),
|
||||
'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ),
|
||||
),
|
||||
'autoload' => false,
|
||||
'desc_tip' => true,
|
||||
'show_if_checked' => 'option',
|
||||
array(
|
||||
'title' => __( 'Shipping destination', 'woocommerce' ),
|
||||
'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_ship_to_destination',
|
||||
'default' => 'billing',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'shipping' => __( 'Default to customer shipping address', 'woocommerce' ),
|
||||
'billing' => __( 'Default to customer billing address', 'woocommerce' ),
|
||||
'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ),
|
||||
),
|
||||
'autoload' => false,
|
||||
'desc_tip' => true,
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => __( 'Debug mode', 'woocommerce' ),
|
||||
'desc' => __( 'Enable debug mode', 'woocommerce' ),
|
||||
'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_shipping_debug_mode',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Debug mode', 'woocommerce' ),
|
||||
'desc' => __( 'Enable debug mode', 'woocommerce' ),
|
||||
'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ),
|
||||
'id' => 'woocommerce_shipping_debug_mode',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'shipping_options',
|
||||
),
|
||||
|
||||
)
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'shipping_options',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
||||
return apply_filters( 'woocommerce_shipping_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,13 +172,10 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
global $current_section, $hide_save_button;
|
||||
|
||||
// Load shipping methods so we can show any global options they may have.
|
||||
$shipping_methods = WC()->shipping()->load_shipping_methods();
|
||||
$shipping_methods = $this->get_shipping_methods();
|
||||
|
||||
if ( '' === $current_section ) {
|
||||
$this->output_zones_screen();
|
||||
} elseif ( 'options' === $current_section ) {
|
||||
$settings = $this->get_settings();
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
} elseif ( 'classes' === $current_section ) {
|
||||
$hide_save_button = true;
|
||||
$this->output_shipping_class_screen();
|
||||
|
@ -167,9 +188,7 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
}
|
||||
}
|
||||
if ( ! $is_shipping_method ) {
|
||||
$settings = $this->get_settings();
|
||||
$settings = apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
parent::output();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,26 +201,25 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
|
||||
switch ( $current_section ) {
|
||||
case 'options':
|
||||
WC_Admin_Settings::save_fields( $this->get_settings() );
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_options' );
|
||||
$this->save_settings_for_current_section();
|
||||
$this->do_update_options_action();
|
||||
break;
|
||||
case 'classes':
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_classes' );
|
||||
$this->do_update_options_action();
|
||||
break;
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
$wc_shipping = WC_Shipping::instance();
|
||||
$is_shipping_method = false;
|
||||
|
||||
foreach ( $wc_shipping->get_shipping_methods() as $method_id => $method ) {
|
||||
foreach ( $this->get_shipping_methods() as $method_id => $method ) {
|
||||
if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ), true ) ) {
|
||||
$is_shipping_method = true;
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $method->id );
|
||||
$this->do_update_options_action( $method->id );
|
||||
}
|
||||
}
|
||||
if ( ! $is_shipping_method ) {
|
||||
WC_Admin_Settings::save_fields( $this->get_settings( $current_section ) );
|
||||
$this->save_settings_for_current_section();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -214,17 +232,19 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
* Handles output of the shipping zones page in admin.
|
||||
*/
|
||||
protected function output_zones_screen() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
global $hide_save_button;
|
||||
|
||||
if ( isset( $_REQUEST['zone_id'] ) ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( isset( $_REQUEST['zone_id'] ) ) {
|
||||
$hide_save_button = true;
|
||||
$this->zone_methods_screen( wc_clean( wp_unslash( $_REQUEST['zone_id'] ) ) ); // WPCS: input var ok, CSRF ok.
|
||||
$this->zone_methods_screen( wc_clean( wp_unslash( $_REQUEST['zone_id'] ) ) );
|
||||
} elseif ( isset( $_REQUEST['instance_id'] ) ) {
|
||||
$this->instance_settings_screen( absint( wp_unslash( $_REQUEST['instance_id'] ) ) ); // WPCS: input var ok, CSRF ok.
|
||||
$this->instance_settings_screen( absint( wp_unslash( $_REQUEST['instance_id'] ) ) );
|
||||
} else {
|
||||
$hide_save_button = true;
|
||||
$this->zones_screen();
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -331,9 +351,10 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
wp_die( esc_html__( 'This shipping method does not have any settings to configure.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['save'] ) ) { // WPCS: input var ok, sanitization ok.
|
||||
if ( ! empty( $_POST['save'] ) ) {
|
||||
|
||||
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'woocommerce-settings' ) ) { // WPCS: input var ok, sanitization ok.
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'woocommerce-settings' ) ) {
|
||||
echo '<div class="updated error"><p>' . esc_html__( 'Edit failed. Please try again.', 'woocommerce' ) . '</p></div>';
|
||||
}
|
||||
|
||||
|
|
|
@ -50,11 +50,11 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get sections.
|
||||
* Get own sections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sections() {
|
||||
protected function get_own_sections() {
|
||||
$sections = array(
|
||||
'' => __( 'Tax options', 'woocommerce' ),
|
||||
'standard' => __( 'Standard rates', 'woocommerce' ),
|
||||
|
@ -68,22 +68,16 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
$sections[ sanitize_title( $class ) ] = sprintf( __( '%s rates', 'woocommerce' ), $class );
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings array.
|
||||
*
|
||||
* @param string $current_section Current section being shown.
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings( $current_section = '' ) {
|
||||
$settings = array();
|
||||
|
||||
if ( '' === $current_section ) {
|
||||
$settings = include __DIR__ . '/views/settings-tax.php';
|
||||
}
|
||||
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
|
||||
public function get_settings_for_default_section() {
|
||||
return include __DIR__ . '/views/settings-tax.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,9 +91,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
if ( 'standard' === $current_section || in_array( $current_section, array_filter( $tax_classes ), true ) ) {
|
||||
$this->output_tax_rates();
|
||||
} else {
|
||||
$settings = $this->get_settings();
|
||||
|
||||
WC_Admin_Settings::output_fields( $settings );
|
||||
parent::output();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,19 +103,18 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
global $current_section;
|
||||
|
||||
if ( ! $current_section ) {
|
||||
$settings = $this->get_settings();
|
||||
WC_Admin_Settings::save_fields( $settings );
|
||||
$this->save_settings_for_current_section();
|
||||
|
||||
if ( isset( $_POST['woocommerce_tax_classes'] ) ) {
|
||||
$this->save_tax_classes( wp_unslash( $_POST['woocommerce_tax_classes'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
}
|
||||
} elseif ( ! empty( $_POST['tax_rate_country'] ) ) {
|
||||
$this->save_tax_rates();
|
||||
} else {
|
||||
$this->save_settings_for_current_section();
|
||||
}
|
||||
|
||||
if ( $current_section ) {
|
||||
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
||||
}
|
||||
$this->do_update_options_action();
|
||||
|
||||
// Invalidate caches.
|
||||
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
|
||||
|
@ -212,8 +203,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
'wc_tax_nonce' => wp_create_nonce( 'wc_tax_nonce-class:' . $current_class ),
|
||||
'base_url' => $base_url,
|
||||
'rates' => array_values( WC_Tax::get_rates_for_tax_class( $current_class ) ),
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
'page' => ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1,
|
||||
'page' => ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1, // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
'limit' => 100,
|
||||
'countries' => $countries,
|
||||
'states' => $states,
|
||||
|
@ -281,6 +271,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
* @return array
|
||||
*/
|
||||
private function get_posted_tax_rate( $key, $order, $class ) {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- this is called from 'save_tax_rates' only, where nonce is already verified.
|
||||
$tax_rate = array();
|
||||
$tax_rate_keys = array(
|
||||
'tax_rate_country',
|
||||
|
@ -304,12 +295,14 @@ class WC_Settings_Tax extends WC_Settings_Page {
|
|||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
|
||||
return $tax_rate;
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
}
|
||||
|
||||
/**
|
||||
* Save tax rates.
|
||||
*/
|
||||
public function save_tax_rates() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- this is called via "do_action('woocommerce_settings_save_'...") in base class, where nonce is verified first.
|
||||
global $wpdb;
|
||||
|
||||
$current_class = sanitize_title( $this->get_current_tax_class() );
|
||||
|
|
|
@ -28,6 +28,7 @@ class WC_CLI {
|
|||
require_once dirname( __FILE__ ) . '/cli/class-wc-cli-rest-command.php';
|
||||
require_once dirname( __FILE__ ) . '/cli/class-wc-cli-tool-command.php';
|
||||
require_once dirname( __FILE__ ) . '/cli/class-wc-cli-update-command.php';
|
||||
require_once dirname( __FILE__ ) . '/cli/class-wc-cli-tracker-command.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,6 +38,7 @@ class WC_CLI {
|
|||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Runner::after_wp_load' );
|
||||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Tool_Command::register_commands' );
|
||||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Update_Command::register_commands' );
|
||||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Tracker_Command::register_commands' );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ class WC_Geolocation {
|
|||
}
|
||||
}
|
||||
|
||||
set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS );
|
||||
set_transient( $transient_name, $external_ip_address, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $external_ip_address;
|
||||
|
@ -161,7 +161,7 @@ class WC_Geolocation {
|
|||
* @param array $geolocation Geolocation data, including country, state, city, and postcode.
|
||||
* @param string $ip_address IP Address.
|
||||
*/
|
||||
$geolocation = apply_filters(
|
||||
$geolocation = apply_filters(
|
||||
'woocommerce_get_geolocation',
|
||||
array(
|
||||
'country' => $country_code,
|
||||
|
@ -302,7 +302,7 @@ class WC_Geolocation {
|
|||
}
|
||||
}
|
||||
|
||||
set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS );
|
||||
set_transient( 'geoip_' . $ip_address, $country_code, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $country_code;
|
||||
|
|
|
@ -603,6 +603,11 @@ class WC_Install {
|
|||
}
|
||||
$subsections = array_unique( array_merge( array( '' ), array_keys( $section->get_sections() ) ) );
|
||||
|
||||
/**
|
||||
* We are using 'WC_Settings_Page::get_settings' on purpose even thought it's deprecated.
|
||||
* See the method documentation for an explanation.
|
||||
*/
|
||||
|
||||
foreach ( $subsections as $subsection ) {
|
||||
foreach ( $section->get_settings( $subsection ) as $value ) {
|
||||
if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
|
||||
|
|
|
@ -114,9 +114,14 @@ class WC_Register_WP_Admin_Settings {
|
|||
$sections = $this->object->get_sections();
|
||||
if ( empty( $sections ) ) {
|
||||
// Default section is just an empty string, per admin page classes.
|
||||
$sections = array( '' );
|
||||
$sections = array( '' => '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* We are using 'WC_Settings_Page::get_settings' on purpose even thought it's deprecated.
|
||||
* See the method documentation for an explanation.
|
||||
*/
|
||||
|
||||
foreach ( $sections as $section => $section_label ) {
|
||||
$settings_from_section = $this->object->get_settings( $section );
|
||||
foreach ( $settings_from_section as $setting ) {
|
||||
|
|
|
@ -96,23 +96,53 @@ class WC_Template_Loader {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the default filename for a template.
|
||||
* Checks whether a block template with that name exists.
|
||||
*
|
||||
* @since 5.5.0
|
||||
* @param string $template_name Template to check.
|
||||
* @return boolean
|
||||
*/
|
||||
private static function has_block_template( $template_name ) {
|
||||
if ( ! $template_name ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_readable(
|
||||
get_stylesheet_directory() . '/block-templates/' . $template_name . '.html'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default filename for a template except if a block template with
|
||||
* the same name exists.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 5.5.0 If a block template with the same name exists, return an
|
||||
* empty string.
|
||||
* @return string
|
||||
*/
|
||||
private static function get_template_loader_default_file() {
|
||||
if ( is_singular( 'product' ) ) {
|
||||
if (
|
||||
is_singular( 'product' ) &&
|
||||
! self::has_block_template( 'single-product' )
|
||||
) {
|
||||
$default_file = 'single-product.php';
|
||||
} elseif ( is_product_taxonomy() ) {
|
||||
$object = get_queried_object();
|
||||
|
||||
if ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
|
||||
$default_file = 'taxonomy-' . $object->taxonomy . '.php';
|
||||
} else {
|
||||
if ( self::has_block_template( 'taxonomy-' . $object->taxonomy ) ) {
|
||||
$default_file = '';
|
||||
} else {
|
||||
$default_file = 'taxonomy-' . $object->taxonomy . '.php';
|
||||
}
|
||||
} elseif ( ! self::has_block_template( 'archive-product' ) ) {
|
||||
$default_file = 'archive-product.php';
|
||||
}
|
||||
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
|
||||
} elseif (
|
||||
( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) &&
|
||||
! self::has_block_template( 'archive-product' )
|
||||
) {
|
||||
$default_file = self::$theme_support ? 'archive-product.php' : '';
|
||||
} else {
|
||||
$default_file = '';
|
||||
|
|
|
@ -113,7 +113,7 @@ class WC_Tracker {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function get_tracking_data() {
|
||||
public static function get_tracking_data() {
|
||||
$data = array();
|
||||
|
||||
// General site info.
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/**
|
||||
* WC_CLI_Tracker_Command class file.
|
||||
*
|
||||
* @package WooCommerce\CLI
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to tracker snapshot for transparency and debugging.
|
||||
*
|
||||
* @since 5.5.0
|
||||
* @package WooCommerce
|
||||
*/
|
||||
class WC_CLI_Tracker_Command {
|
||||
|
||||
/**
|
||||
* Registers a command for showing WooCommerce Tracker snapshot data.
|
||||
*/
|
||||
public static function register_commands() {
|
||||
WP_CLI::add_command( 'wc tracker snapshot', array( 'WC_CLI_Tracker_Command', 'show_tracker_snapshot' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump tracker snapshot data to screen.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp wc tracker snapshot --format=yaml
|
||||
* wp wc tracker snapshot --format=json
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* [--format=<format>]
|
||||
* : Render output in a particular format, see WP_CLI\Formatter for details.
|
||||
*
|
||||
* @see \WP_CLI\Formatter
|
||||
* @see WC_Tracker::get_tracking_data()
|
||||
* @param array $args WP-CLI positional arguments.
|
||||
* @param array $assoc_args WP-CLI associative arguments.
|
||||
*/
|
||||
public static function show_tracker_snapshot( $args, $assoc_args ) {
|
||||
$snapshot_data = WC_Tracker::get_tracking_data();
|
||||
|
||||
$formatter = new \WP_CLI\Formatter(
|
||||
$assoc_args,
|
||||
array_keys( $snapshot_data )
|
||||
);
|
||||
|
||||
$formatter->display_items( array( $snapshot_data ) );
|
||||
}
|
||||
}
|
|
@ -49,8 +49,4 @@
|
|||
<listeners>
|
||||
<listener class="SpeedTrapListener" file="tests/legacy/includes/listener-loader.php" />
|
||||
</listeners>
|
||||
<extensions>
|
||||
<extension class="\Automattic\WooCommerce\Testing\Tools\CodeHacking\CodeHackerTestHook" />
|
||||
<extension class="\Automattic\WooCommerce\Testing\Tools\DependencyManagement\DependencyManagementTestHook" />
|
||||
</extensions>
|
||||
</phpunit>
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* CodeHackerTestHook class file.
|
||||
*
|
||||
* @package WooCommerce\Testing
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Testing\Tools\CodeHacking;
|
||||
|
||||
use PHPUnit\Runner\BeforeTestHook;
|
||||
|
||||
/**
|
||||
* Helper to use the CodeHacker class in PHPUnit. To use, add this to phpunit.xml:
|
||||
*
|
||||
* <extensions>
|
||||
* <extension class="CodeHackerTestHook" />
|
||||
* </extensions>
|
||||
*/
|
||||
final class CodeHackerTestHook implements BeforeTestHook {
|
||||
|
||||
/**
|
||||
* Runs before each test.
|
||||
*
|
||||
* @param string $test "TestClass::TestMethod".
|
||||
*
|
||||
* @throws \ReflectionException Thrown by execute_before_methods.
|
||||
*/
|
||||
public function executeBeforeTest( string $test ): void {
|
||||
CodeHacker::reset_hacks();
|
||||
}
|
||||
}
|
||||
|
|
@ -130,9 +130,9 @@ final class FunctionsMockerHack extends CodeHack {
|
|||
if ( ! is_callable( $mock ) ) {
|
||||
throw new \Exception( "FunctionsMockerHack::add_function_mocks: The mock supplied for '$function_name' isn't callable." );
|
||||
}
|
||||
}
|
||||
|
||||
$this->function_mocks = array_merge( $this->function_mocks, $mocks );
|
||||
$this->function_mocks[ $function_name ] = $mock;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -132,10 +132,10 @@ final class StaticMockerHack extends CodeHack {
|
|||
if ( ! in_array( $class_name, $this->mockable_classes, true ) ) {
|
||||
throw new \Exception( "FunctionsMockerHack::add_function_mocks: Can't mock methods of the '$class_name' class since it isn't in the list of mockable classes supplied to 'initialize'." );
|
||||
}
|
||||
|
||||
$this->method_mocks[ $class_name ][ $method_name ] = $method_mock;
|
||||
}
|
||||
}
|
||||
|
||||
$this->method_mocks = array_merge_recursive( $this->method_mocks, $mocks );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* DependencyManagementTestHook class file.
|
||||
*
|
||||
* @package Automattic\WooCommerce\Testing\Tools\DependencyManagement
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Testing\Tools\DependencyManagement;
|
||||
|
||||
use Automattic\WooCommerce\Proxies\LegacyProxy;
|
||||
use PHPUnit\Runner\BeforeTestHook;
|
||||
|
||||
/**
|
||||
* Hook to perform dependency management related setup in PHPUnit. To use, add this to phpunit.xml:
|
||||
*
|
||||
* <extensions>
|
||||
* <extension class="DependencyManagementTestHook" />
|
||||
* </extensions>
|
||||
*/
|
||||
final class DependencyManagementTestHook implements BeforeTestHook {
|
||||
|
||||
/**
|
||||
* Runs before each test.
|
||||
*
|
||||
* @param string $test "TestClass::TestMethod".
|
||||
*/
|
||||
public function executeBeforeTest( string $test ): void {
|
||||
// Reset the instance of MockableLegacyProxy that was registered during bootstrap,
|
||||
// in order to start the test in a clean state (without anything mocked).
|
||||
wc_get_container()->get( LegacyProxy::class )->reset();
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ const {
|
|||
uiUnblocked,
|
||||
applyCoupon,
|
||||
removeCoupon,
|
||||
waitForSelectorWithoutThrow,
|
||||
} = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
/**
|
||||
|
@ -33,6 +34,7 @@ const runCheckoutApplyCouponsTest = () => {
|
|||
couponFixedProduct = await createCoupon('5', 'Fixed product discount');
|
||||
await shopper.emptyCart();
|
||||
await shopper.goToShop();
|
||||
await waitForSelectorWithoutThrow( '.add_to_cart_button' );
|
||||
await shopper.addToCartFromShopPage('Simple product');
|
||||
await uiUnblocked();
|
||||
await shopper.goToCheckout();
|
||||
|
|
|
@ -166,7 +166,7 @@ To implement the Slackbot in your CI:
|
|||
|
||||
- Create a [Slackbot App](https://slack.com/help/articles/115005265703-Create-a-bot-for-your-workspace)
|
||||
- Give the app the following permissions:
|
||||
- `channel:join`
|
||||
- `channels:join`
|
||||
- `chat:write`
|
||||
- `files:write`
|
||||
- `incoming-webhook`
|
||||
|
|
|
@ -8,5 +8,10 @@
|
|||
*/
|
||||
|
||||
return array(
|
||||
// 'WC_Admin_Settings'
|
||||
'WC_Admin_API_Keys',
|
||||
'WC_Admin_Settings',
|
||||
'WC_Admin_Webhooks',
|
||||
'WC_Emails',
|
||||
'WC_Payment_Gateways',
|
||||
'WC_Tax',
|
||||
);
|
||||
|
|
|
@ -77,6 +77,12 @@ class WC_Unit_Test_Case extends WP_HTTP_TestCase {
|
|||
// Register post types before each test.
|
||||
WC_Post_types::register_post_types();
|
||||
WC_Post_types::register_taxonomies();
|
||||
|
||||
CodeHacker::reset_hacks();
|
||||
|
||||
// Reset the instance of MockableLegacyProxy that was registered during bootstrap,
|
||||
// in order to start the test in a clean state (without anything mocked).
|
||||
wc_get_container()->get( LegacyProxy::class )->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,6 +254,71 @@ class WC_Unit_Test_Case extends WP_HTTP_TestCase {
|
|||
wc_get_container()->get( LegacyProxy::class )->register_class_mocks( $mocks );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a certain callable output is equivalent to a given piece of HTML.
|
||||
*
|
||||
* "Equivalent" means that the string representations of the HTML pieces are equal
|
||||
* except for line breaks, tabs and redundant whitespace.
|
||||
*
|
||||
* @param string $expected The expected HTML.
|
||||
* @param callable $callable The callable that is supposed to output the expected HTML.
|
||||
* @param string $message Optional error message to display if the assertion fails.
|
||||
*/
|
||||
protected function assertOutputsHTML( $expected, $callable, $message = '' ) {
|
||||
$actual = $this->capture_output_from( $callable );
|
||||
$this->assertEqualsHTML( $expected, $actual, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two pieces of HTML are equivalent.
|
||||
*
|
||||
* "Equivalent" means that the string representations of the HTML pieces are equal
|
||||
* except for line breaks, tabs and redundant whitespace.
|
||||
*
|
||||
* @param string $expected The expected HTML.
|
||||
* @param string $actual The HTML that is supposed to be equivalent to the expected one.
|
||||
* @param string $message Optional error message to display if the assertion fails.
|
||||
*/
|
||||
protected function assertEqualsHTML( $expected, $actual, $message = '' ) {
|
||||
$this->assertEquals( $this->normalize_html( $expected ), $this->normalize_html( $actual ), $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a block of HTML.
|
||||
* Line breaks, tabs and redundand whitespaces are removed.
|
||||
*
|
||||
* @param string $html The block of HTML to normalize.
|
||||
*
|
||||
* @return string The normalized block.
|
||||
*/
|
||||
protected function normalize_html( $html ) {
|
||||
$html = $this->filter_output( $html );
|
||||
$html = str_replace( '&', '&', $html );
|
||||
$html = preg_replace( '/> +</', '><', $html );
|
||||
|
||||
$doc = new DomDocument();
|
||||
$doc->preserveWhiteSpace = false; //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
$doc->loadHTML( $html );
|
||||
|
||||
return $doc->saveHTML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a callable, captures its output and returns it.
|
||||
*
|
||||
* @param callable $callable Callable to execute.
|
||||
* @param mixed ...$params Parameters to pass to the callable as arguments.
|
||||
*
|
||||
* @return false|string The output generated by the callable, or false if there is an error.
|
||||
*/
|
||||
protected function capture_output_from( $callable, ...$params ) {
|
||||
ob_start();
|
||||
call_user_func( $callable, ...$params );
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is of type int.
|
||||
* TODO: After upgrading to PHPUnit 8 or newer, remove this method and replace calls with PHPUnit's built-in 'assertIsInt'.
|
||||
|
|
|
@ -8,5 +8,10 @@
|
|||
*/
|
||||
|
||||
return array(
|
||||
'current_user_can',
|
||||
'get_bloginfo',
|
||||
'get_woocommerce_currencies',
|
||||
'get_woocommerce_currency_symbol',
|
||||
'wc_get_shipping_method_count',
|
||||
'wc_site_is_https',
|
||||
);
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* WC_Tests_Register_WP_Admin_Settings class file.
|
||||
*
|
||||
* @package @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
/**
|
||||
* Settings API: WP-Admin Helper Tests
|
||||
|
@ -21,7 +26,6 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// $mock_page = $this->getMock( 'WC_Settings_General' );
|
||||
$mock_page = $this->getMockBuilder( 'WC_Settings_General' )->getMock();
|
||||
|
||||
$mock_page
|
||||
|
@ -77,7 +81,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
*/
|
||||
public function register_setting_provider() {
|
||||
return array(
|
||||
// No "id" case
|
||||
// No "id" case.
|
||||
array(
|
||||
array(
|
||||
'type' => 'some-type-with-no-id',
|
||||
|
@ -85,7 +89,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
),
|
||||
false,
|
||||
),
|
||||
// All optional properties except 'desc_tip'
|
||||
// All optional properties except 'desc_tip'.
|
||||
array(
|
||||
array(
|
||||
'id' => 'setting-id',
|
||||
|
@ -106,7 +110,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
'option_key' => '',
|
||||
),
|
||||
),
|
||||
// Boolean 'desc_tip' defaulting to 'desc' value
|
||||
// Boolean 'desc_tip' defaulting to 'desc' value.
|
||||
array(
|
||||
array(
|
||||
'id' => 'setting-id',
|
||||
|
@ -125,7 +129,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
'option_key' => '',
|
||||
),
|
||||
),
|
||||
// String 'desc_tip'
|
||||
// String 'desc_tip'.
|
||||
array(
|
||||
array(
|
||||
'id' => 'setting-id',
|
||||
|
@ -144,7 +148,8 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
'option_key' => '',
|
||||
),
|
||||
),
|
||||
// Empty 'title' and 'desc'
|
||||
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
|
||||
// Empty 'title' and empty 'desc'.
|
||||
array(
|
||||
array(
|
||||
'id' => 'setting-id',
|
||||
|
@ -166,6 +171,8 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
* @since 3.0.0
|
||||
* @dataProvider register_setting_provider
|
||||
* @covers WC_Register_WP_Admin_Settings::register_setting
|
||||
* @param array $input Array of settings.
|
||||
* @param bool $expected Expected result of the setting registering operation.
|
||||
*/
|
||||
public function test_register_setting( $input, $expected ) {
|
||||
$settings = new WC_Register_WP_Admin_Settings( $this->page, 'page' );
|
||||
|
@ -179,7 +186,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
* @since 3.0.0
|
||||
* @covers WC_Register_WP_Admin_Settings::register_page_settings
|
||||
*/
|
||||
public function test_register_settings_one_section() {
|
||||
public function test_register_settings_default_section_no_settings() {
|
||||
$this->page
|
||||
->expects( $this->any() )
|
||||
->method( 'get_sections' )
|
||||
|
@ -188,7 +195,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
$this->page
|
||||
->expects( $this->once() )
|
||||
->method( 'get_settings' )
|
||||
->with( $this->equalTo( 0 ) )
|
||||
->with( $this->equalTo( '' ) )
|
||||
->will( $this->returnValue( array() ) );
|
||||
|
||||
$settings = new WC_Register_WP_Admin_Settings( $this->page, 'page' );
|
||||
|
@ -203,7 +210,7 @@ class WC_Tests_Register_WP_Admin_Settings extends WC_Unit_Test_Case {
|
|||
* @since 3.0.0
|
||||
* @covers WC_Register_WP_Admin_Settings::register_page_settings
|
||||
*/
|
||||
public function test_register_settings() {
|
||||
public function test_register_settings_default_section_with_settings() {
|
||||
$this->page
|
||||
->expects( $this->any() )
|
||||
->method( 'get_sections' )
|
||||
|
|
|
@ -28,7 +28,7 @@ class WC_Discounts_Tests extends WC_Unit_Test_Case {
|
|||
* Helper method to create customer.
|
||||
*/
|
||||
public function create_customer() {
|
||||
$username = 'testusername-' . microtime( true ) . wp_generate_password( 6, false, false );
|
||||
$username = sanitize_title( 'testusername-' . microtime( true ) . wp_generate_password( 6, false, false ) );
|
||||
$customer = new WC_Customer();
|
||||
$customer->set_username( $username );
|
||||
$customer->set_password( 'test123' );
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Legacy_Settings_Example file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper class to test base functionality of WC_Settings_Page.
|
||||
* This simulates a legacy class that overrides the get_settings method directly.
|
||||
*/
|
||||
class WC_Legacy_Settings_Example extends WC_Settings_Page {
|
||||
// phpcs:disable Squiz.Commenting.FunctionComment.Missing
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'example';
|
||||
$this->label = 'Example';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function get_settings() {
|
||||
return array( 'foo' => 'bar' );
|
||||
}
|
||||
|
||||
// phpcs:enable Squiz.Commenting.FunctionComment.Missing
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Accounts_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_General class.
|
||||
*/
|
||||
class WC_Settings_Accounts_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test for get_settings (triggers the woocommerce_account_settings filter).
|
||||
*/
|
||||
public function test_get_settings__triggers_filter() {
|
||||
$actual_settings_via_filter = null;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_account_settings',
|
||||
function( $settings ) use ( &$actual_settings_via_filter ) {
|
||||
$actual_settings_via_filter = $settings;
|
||||
return $settings;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Accounts();
|
||||
|
||||
$actual_settings_returned = $sut->get_settings_for_section( '' );
|
||||
remove_all_filters( 'woocommerce_account_settings' );
|
||||
|
||||
$this->assertSame( $actual_settings_returned, $actual_settings_via_filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings (all settings are present).
|
||||
*/
|
||||
public function test_get_settings__all_settings_are_present() {
|
||||
$sut = new WC_Settings_Accounts();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'account_registration_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_enable_guest_checkout' => 'checkbox',
|
||||
'woocommerce_enable_checkout_login_reminder' => 'checkbox',
|
||||
'woocommerce_enable_signup_and_login_from_checkout' => 'checkbox',
|
||||
'woocommerce_enable_myaccount_registration' => 'checkbox',
|
||||
'woocommerce_registration_generate_username' => 'checkbox',
|
||||
'woocommerce_registration_generate_password' => 'checkbox',
|
||||
'woocommerce_erasure_request_removes_order_data' => 'checkbox',
|
||||
'woocommerce_erasure_request_removes_download_data' => 'checkbox',
|
||||
'woocommerce_allow_bulk_remove_personal_data' => 'checkbox',
|
||||
'privacy_policy_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_registration_privacy_policy_text' => 'textarea',
|
||||
'woocommerce_checkout_privacy_policy_text' => 'textarea',
|
||||
'personal_data_retention' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_delete_inactive_accounts' => 'relative_date_selector',
|
||||
'woocommerce_trash_pending_orders' => 'relative_date_selector',
|
||||
'woocommerce_trash_failed_orders' => 'relative_date_selector',
|
||||
'woocommerce_trash_cancelled_orders' => 'relative_date_selector',
|
||||
'woocommerce_anonymize_completed_orders' => 'relative_date_selector',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_linked_text_for_erasure_request_settings.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data_provider_for_test_linked_text_for_erasure_request_settings() {
|
||||
return array(
|
||||
array(
|
||||
false,
|
||||
null,
|
||||
'When handling an account erasure request, should personal data within orders be retained or removed?',
|
||||
'When handling an account erasure request, should access to downloadable files be revoked and download logs cleared?',
|
||||
),
|
||||
array(
|
||||
true,
|
||||
'5.2',
|
||||
'When handling an <a href="http://example.org/wp-admin/tools.php?page=remove_personal_data">account erasure request</a>, should personal data within orders be retained or removed?',
|
||||
'When handling an <a href="http://example.org/wp-admin/tools.php?page=remove_personal_data">account erasure request</a>, should access to downloadable files be revoked and download logs cleared?',
|
||||
),
|
||||
array(
|
||||
true,
|
||||
'5.3',
|
||||
'When handling an <a href="http://example.org/wp-admin/erase-personal-data.php">account erasure request</a>, should personal data within orders be retained or removed?',
|
||||
'When handling an <a href="http://example.org/wp-admin/erase-personal-data.php">account erasure request</a>, should access to downloadable files be revoked and download logs cleared?',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the "account erasure request" text is linked or not as appropriate for descriptions of account erasure request related options.
|
||||
*
|
||||
* @dataProvider data_provider_for_test_linked_text_for_erasure_request_settings
|
||||
*
|
||||
* @param bool $current_user_can_manage_privacy_options Can the current user manage privacy options?.
|
||||
* @param string $blog_version Current blog version.
|
||||
* @param string $expected_order_erasure_text Expected description for the remove order data option.
|
||||
* @param string $expected_downloads_erasure_text Expected description for the remove downloads data option.
|
||||
*/
|
||||
public function test_linked_text_for_erasure_request_settings( $current_user_can_manage_privacy_options, $blog_version, $expected_order_erasure_text, $expected_downloads_erasure_text ) {
|
||||
FunctionsMockerHack::add_function_mocks(
|
||||
array(
|
||||
'current_user_can' => function( $capability, ...$args ) use ( $current_user_can_manage_privacy_options ) {
|
||||
return 'manage_privacy_options' === $capability ?
|
||||
$current_user_can_manage_privacy_options :
|
||||
current_user_can( $capability, ...$args );
|
||||
},
|
||||
'get_bloginfo' => function( $show = '', $filter = 'raw' ) use ( $blog_version ) {
|
||||
return 'version' === $show ?
|
||||
$blog_version :
|
||||
get_bloginfo( $show, $filter );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Accounts();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
|
||||
$order_data_removal_setting = $this->setting_by_id( $settings, 'woocommerce_erasure_request_removes_order_data' );
|
||||
$actual_desc = $order_data_removal_setting['desc_tip'];
|
||||
$this->assertEquals( $expected_order_erasure_text, $actual_desc );
|
||||
|
||||
$downloads_data_removal_setting = $this->setting_by_id( $settings, 'woocommerce_erasure_request_removes_download_data' );
|
||||
$actual_desc = $downloads_data_removal_setting['desc_tip'];
|
||||
$this->assertEquals( $expected_downloads_erasure_text, $actual_desc );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,419 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Advanced_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_Advanced class.
|
||||
*/
|
||||
class WC_Settings_Advanced_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox get_sections should get all the existing sections.
|
||||
*/
|
||||
public function test_get_sections() {
|
||||
$sut = new WC_Settings_Advanced();
|
||||
|
||||
$section_names = array_keys( $sut->get_sections() );
|
||||
|
||||
$expected = array(
|
||||
'',
|
||||
'keys',
|
||||
'webhooks',
|
||||
'legacy_api',
|
||||
'woocommerce_com',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $section_names );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_settings should trigger the appropriate filter depending on the requested section name.
|
||||
*
|
||||
* @testWith ["", "woocommerce_settings_pages"]
|
||||
* ["woocommerce_com", "woocommerce_com_integration_settings"]
|
||||
* ["legacy_api", "woocommerce_settings_rest_api"]
|
||||
*
|
||||
* @param string $section_name The section name to test getting the settings for.
|
||||
* @param string $filter_name The name of the filter that is expected to be triggered.
|
||||
*/
|
||||
public function test_get_settings_triggers_filter( $section_name, $filter_name ) {
|
||||
$actual_settings_via_filter = null;
|
||||
|
||||
add_filter(
|
||||
$filter_name,
|
||||
function ( $settings ) use ( &$actual_settings_via_filter ) {
|
||||
$actual_settings_via_filter = $settings;
|
||||
|
||||
return $settings;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
|
||||
$actual_settings_returned = $sut->get_settings_for_section( $section_name );
|
||||
remove_all_filters( $filter_name );
|
||||
|
||||
$this->assertSame( $actual_settings_returned, $actual_settings_via_filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('') should return all the settings for the default section.
|
||||
*
|
||||
* @testWith [true]
|
||||
* [false]
|
||||
*
|
||||
* @param bool $site_is_https Return value for wc_site_is_https.
|
||||
*/
|
||||
public function test_get_default_settings_returns_all_settings( $site_is_https ) {
|
||||
$sut = new WC_Settings_Advanced();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
update_option( 'home', $site_is_https ? 'https://foo.bar' : 'http://foo.bar' );
|
||||
|
||||
$expected = array(
|
||||
'advanced_page_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_cart_page_id' => 'single_select_page_with_search',
|
||||
'woocommerce_checkout_page_id' => 'single_select_page_with_search',
|
||||
'woocommerce_myaccount_page_id' => 'single_select_page_with_search',
|
||||
'woocommerce_terms_page_id' => 'single_select_page_with_search',
|
||||
'checkout_process_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_force_ssl_checkout' => 'checkbox',
|
||||
'woocommerce_unforce_ssl_checkout' => 'checkbox',
|
||||
'checkout_endpoint_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_checkout_pay_endpoint' => 'text',
|
||||
'woocommerce_checkout_order_received_endpoint' => 'text',
|
||||
'woocommerce_myaccount_add_payment_method_endpoint' => 'text',
|
||||
'woocommerce_myaccount_delete_payment_method_endpoint' => 'text',
|
||||
'woocommerce_myaccount_set_default_payment_method_endpoint' => 'text',
|
||||
'account_endpoint_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_myaccount_orders_endpoint' => 'text',
|
||||
'woocommerce_myaccount_view_order_endpoint' => 'text',
|
||||
'woocommerce_myaccount_downloads_endpoint' => 'text',
|
||||
'woocommerce_myaccount_edit_account_endpoint' => 'text',
|
||||
'woocommerce_myaccount_edit_address_endpoint' => 'text',
|
||||
'woocommerce_myaccount_payment_methods_endpoint' => 'text',
|
||||
'woocommerce_myaccount_lost_password_endpoint' => 'text',
|
||||
'woocommerce_logout_endpoint' => 'text',
|
||||
);
|
||||
|
||||
if ( $site_is_https ) {
|
||||
unset( $expected['unforce_ssl_checkout'], $expected['force_ssl_checkout'] );
|
||||
}
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('') should take the cart page id from the woocommerce_cart_shortcode_tag filter.
|
||||
*/
|
||||
public function test_get_default_settings_takes_cart_page_id_from_filter() {
|
||||
$original_id = null;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_cart_shortcode_tag',
|
||||
function ( $id ) use ( &$original_id ) {
|
||||
$original_id = $id;
|
||||
return 'foobar';
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$setting = current(
|
||||
array_filter(
|
||||
$settings,
|
||||
function( $value ) {
|
||||
return 'woocommerce_cart_page_id' === $value['id'];
|
||||
}
|
||||
)
|
||||
);
|
||||
$actual_setting_desc = $setting['desc'];
|
||||
|
||||
$this->assertEquals( 'woocommerce_cart', $original_id );
|
||||
$this->assertEquals( 'Page contents: [foobar]', $actual_setting_desc );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('woocommerce_com') should return all the settings for the woocommerce_com section.
|
||||
*/
|
||||
public function test_get_woocommerce_com_settings_returns_all_settings() {
|
||||
$sut = new WC_Settings_Advanced();
|
||||
|
||||
$expected = array(
|
||||
'tracking_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_allow_tracking' => 'checkbox',
|
||||
'marketplace_suggestions' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_show_marketplace_suggestions' => 'checkbox',
|
||||
);
|
||||
|
||||
$settings = $sut->get_settings_for_section( 'woocommerce_com' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('legacy_api') should return all the settings for the legacy_api section.
|
||||
*/
|
||||
public function test_get_legacy_api_settings_returns_all_settings() {
|
||||
$sut = new WC_Settings_Advanced();
|
||||
|
||||
$expected = array(
|
||||
'legacy_api_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_api_enabled' => 'checkbox',
|
||||
);
|
||||
|
||||
$settings = $sut->get_settings_for_section( 'legacy_api' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox output method should invoke the output method of the appropriate class depending on the section.
|
||||
*
|
||||
* @testWith ["webhooks", "WC_Admin_Webhooks"]
|
||||
* ["keys", "WC_Admin_API_Keys"]
|
||||
* ["foobar", "WC_Admin_Settings"]
|
||||
*
|
||||
* @param string $current_section_to_use The section to set as the current one for the test.
|
||||
* @param string $expected_invoked_class The name of the class whose output method is expected to be invoked.
|
||||
*/
|
||||
public function test_output_invokes_the_appropriate_class( $current_section_to_use, $expected_invoked_class ) {
|
||||
global $current_section;
|
||||
|
||||
$actual_invoked_class = null;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Webhooks' => array(
|
||||
'page_output' => function() use ( &$actual_invoked_class ) {
|
||||
$actual_invoked_class = 'WC_Admin_Webhooks';
|
||||
},
|
||||
),
|
||||
'WC_Admin_API_Keys' => array(
|
||||
'page_output' => function() use ( &$actual_invoked_class ) {
|
||||
$actual_invoked_class = 'WC_Admin_API_Keys';
|
||||
},
|
||||
),
|
||||
'WC_Admin_Settings' => array(
|
||||
'output_fields' => function( $settings ) use ( &$actual_invoked_class ) {
|
||||
$actual_invoked_class = 'WC_Admin_Settings';
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$current_section = $current_section_to_use;
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertEquals( $expected_invoked_class, $actual_invoked_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The notices method of the appropriate class should be invoked on instantiation.
|
||||
*
|
||||
* @testWith ["webhooks", "WC_Admin_Webhooks"]
|
||||
* ["keys", "WC_Admin_API_Keys"]
|
||||
* ["foobar", null]
|
||||
*
|
||||
* @param string $section_in_query_string Section name to be simulated in the query string.
|
||||
* @param string $expected_notices_class_invoked Class whose notices method is expected to be invoked, null for none.
|
||||
*/
|
||||
public function test_notices_are_invoked_on_class_instantiation( $section_in_query_string, $expected_notices_class_invoked ) {
|
||||
$actual_invoked_class = null;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Webhooks' => array(
|
||||
'notices' => function() use ( &$actual_invoked_class ) {
|
||||
$actual_invoked_class = 'WC_Admin_Webhooks';
|
||||
},
|
||||
),
|
||||
'WC_Admin_API_Keys' => array(
|
||||
'notices' => function() use ( &$actual_invoked_class ) {
|
||||
$actual_invoked_class = 'WC_Admin_API_Keys';
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$_GET['section'] = $section_in_query_string;
|
||||
|
||||
new WC_Settings_Advanced();
|
||||
|
||||
$this->assertEquals( $expected_notices_class_invoked, $actual_invoked_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox save method should use the woocommerce_rest_api_valid_to_save filter to check if it's ok to save.
|
||||
*
|
||||
* @testWith ["keys", false]
|
||||
* ["webhooks", false]
|
||||
* ["foobar", true]
|
||||
*
|
||||
* @param string $current_section_to_use Section to be set as current for the test.
|
||||
* @param bool $expected_filter_supplied_value Expected default value to be passed to the filter.
|
||||
*/
|
||||
public function test_save_uses_filter_to_check_if_valid_to_save( $current_section_to_use, $expected_filter_supplied_value ) {
|
||||
global $current_section;
|
||||
|
||||
$actual_filter_supplied_value = null;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_rest_api_valid_to_save',
|
||||
function ( $value ) use ( &$actual_filter_supplied_value ) {
|
||||
$actual_filter_supplied_value = $value;
|
||||
|
||||
return false;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$current_section = $current_section_to_use;
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
$sut->save();
|
||||
|
||||
remove_all_filters( 'woocommerce_rest_api_valid_to_save' );
|
||||
|
||||
$this->assertEquals( $expected_filter_supplied_value, $actual_filter_supplied_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox save method should save data only if the woocommerce_rest_api_valid_to_save filter returns true.
|
||||
*
|
||||
* @testWith [true]
|
||||
* [false]
|
||||
*
|
||||
* @param bool $is_valid_to_save Return value of the woocommerce_rest_api_valid_to_save filter.
|
||||
*/
|
||||
public function test_save_saves_data_only_if_valid_to_save( $is_valid_to_save ) {
|
||||
$settings_were_saved = false;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_rest_api_valid_to_save',
|
||||
function ( $value ) use ( &$is_valid_to_save ) {
|
||||
return $is_valid_to_save;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Settings' => array(
|
||||
'save_fields' => function( $settings ) use ( &$settings_were_saved ) {
|
||||
$settings_were_saved = true;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
$sut->save();
|
||||
|
||||
remove_all_filters( 'woocommerce_rest_api_valid_to_save' );
|
||||
|
||||
$this->assertEquals( $is_valid_to_save, $settings_were_saved );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox save method should trigger the appropriate woocommerce_update_options action only if it's ok to save.
|
||||
*
|
||||
* @testWith [true]
|
||||
* [false]
|
||||
*
|
||||
* @param bool $is_valid_to_save Return value of the woocommerce_rest_api_valid_to_save filter.
|
||||
*/
|
||||
public function test_save_does_updated_options_action_if_valid_to_save( $is_valid_to_save ) {
|
||||
global $current_section;
|
||||
|
||||
$current_section = 'foobar';
|
||||
remove_all_filters( 'woocommerce_update_options_advanced_foobar' );
|
||||
|
||||
add_filter(
|
||||
'woocommerce_rest_api_valid_to_save',
|
||||
function ( $value ) use ( &$is_valid_to_save ) {
|
||||
return $is_valid_to_save;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
$sut->save();
|
||||
|
||||
remove_all_filters( 'woocommerce_rest_api_valid_to_save' );
|
||||
|
||||
$did_action = $is_valid_to_save ? 1 : 0;
|
||||
$this->assertEquals( $did_action, did_action( 'woocommerce_update_options_advanced_foobar' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox save method should prevent the terms and the checkout page ids from being the same.
|
||||
*
|
||||
* @testWith ["foo", "bar", "foo"]
|
||||
* ["foo", "foo", ""]
|
||||
*
|
||||
* @param string $terms_page_id Terms page id in the request.
|
||||
* @param string $checkout_page_id Checkout page id in the request.
|
||||
* @param string $expected_new_terms_page_id Terms page id in the request (possibly modified) after save.
|
||||
*/
|
||||
public function test_save_prevents_the_terms_and_checkout_pages_from_being_the_same( $terms_page_id, $checkout_page_id, $expected_new_terms_page_id ) {
|
||||
$_POST['woocommerce_terms_page_id'] = $terms_page_id;
|
||||
$_POST['woocommerce_checkout_page_id'] = $checkout_page_id;
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
$sut->save();
|
||||
|
||||
// phpcs:ignore WordPress.Security
|
||||
$this->assertEquals( $expected_new_terms_page_id, $_POST['woocommerce_terms_page_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* * @testdox save method should prevent the cart, checkout and my account page ids from being the same.
|
||||
*
|
||||
* @testWith ["cart", "checkout", "myaccount", "checkout", "myaccount"]
|
||||
* ["cartcheckout", "cartcheckout", "myaccount", "", "myaccount"]
|
||||
* ["cartmyaccount", "checkout", "cartmyaccount", "checkout", ""]
|
||||
* ["cart", "checkoutmyaccount", "checkoutmyaccount", "checkoutmyaccount", ""]
|
||||
*
|
||||
* @param string $cart_page_id Cart page id in the request.
|
||||
* @param string $checkout_page_id Checkout page id in the request.
|
||||
* @param string $my_account_page_id My account page id in the request.
|
||||
* @param string $expected_new_checkout_page_id Checkout page id in the request (possibly modified) after save.
|
||||
* @param string $expected_new_my_account_page_id My account page id in the request (possibly modified) after save.
|
||||
*/
|
||||
public function test_save_prevents_the_cart_checkout_and_my_account_pages_from_being_the_same( $cart_page_id, $checkout_page_id, $my_account_page_id, $expected_new_checkout_page_id, $expected_new_my_account_page_id ) {
|
||||
$_POST['woocommerce_cart_page_id'] = $cart_page_id;
|
||||
$_POST['woocommerce_checkout_page_id'] = $checkout_page_id;
|
||||
$_POST['woocommerce_myaccount_page_id'] = $my_account_page_id;
|
||||
|
||||
$sut = new WC_Settings_Advanced();
|
||||
$sut->save();
|
||||
|
||||
// phpcs:disable WordPress.Security
|
||||
$this->assertEquals( $expected_new_checkout_page_id, $_POST['woocommerce_checkout_page_id'] );
|
||||
$this->assertEquals( $expected_new_my_account_page_id, $_POST['woocommerce_myaccount_page_id'] );
|
||||
// phpcs:enable WordPress.Security
|
||||
}
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Emails_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_Email class.
|
||||
*/
|
||||
class WC_Settings_Emails_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox get_sections should get all the existing sections.
|
||||
*/
|
||||
public function test_get_sections() {
|
||||
$sut = new WC_Settings_Emails();
|
||||
|
||||
$section_names = array_keys( $sut->get_sections() );
|
||||
|
||||
$expected = array(
|
||||
'',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $section_names );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_settings should trigger the appropriate filter depending on the requested section name.
|
||||
*
|
||||
* @testWith ["", "woocommerce_email_settings"]
|
||||
*
|
||||
* @param string $section_name The section name to test getting the settings for.
|
||||
* @param string $filter_name The name of the filter that is expected to be triggered.
|
||||
*/
|
||||
public function test_get_settings_triggers_filter( $section_name, $filter_name ) {
|
||||
$actual_settings_via_filter = null;
|
||||
|
||||
add_filter(
|
||||
$filter_name,
|
||||
function ( $settings ) use ( &$actual_settings_via_filter ) {
|
||||
$actual_settings_via_filter = $settings;
|
||||
|
||||
return $settings;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Emails();
|
||||
|
||||
$actual_settings_returned = $sut->get_settings_for_section( $section_name );
|
||||
remove_all_filters( $filter_name );
|
||||
|
||||
$this->assertSame( $actual_settings_returned, $actual_settings_via_filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('') should return all the settings for the default section.
|
||||
*/
|
||||
public function test_get_default_settings_returns_all_settings() {
|
||||
$sut = new WC_Settings_Emails();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'email_notification_settings' => array( 'title', 'sectionend' ),
|
||||
'' => 'email_notification',
|
||||
'email_recipient_options' => 'sectionend',
|
||||
'email_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_email_from_name' => 'text',
|
||||
'woocommerce_email_from_address' => 'email',
|
||||
'email_template_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_email_header_image' => 'text',
|
||||
'woocommerce_email_footer_text' => 'textarea',
|
||||
'woocommerce_email_base_color' => 'color',
|
||||
'woocommerce_email_background_color' => 'color',
|
||||
'woocommerce_email_body_background_color' => 'color',
|
||||
'woocommerce_email_text_color' => 'color',
|
||||
'email_merchant_notes' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_merchant_email_notifications' => 'checkbox',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox When the current section is the name of an existing email, 'output' invokes that email's 'admin_options' method.
|
||||
*/
|
||||
public function test_output_is_done_via_admin_options_method_of_email_specified_as_settings_section() {
|
||||
global $current_section;
|
||||
$current_section = 'wc_email_new_order';
|
||||
|
||||
$admin_options_invoked = false;
|
||||
$actual_email = null;
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Emails::class )
|
||||
->setMethods( array( 'run_email_admin_options' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'run_email_admin_options' )
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function( $email ) use ( &$admin_options_invoked, &$actual_email ) {
|
||||
$admin_options_invoked = true;
|
||||
$actual_email = $email;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertTrue( $admin_options_invoked );
|
||||
$this->assertInstanceOf( WC_Email_New_Order::class, $actual_email );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'save' will trigger 'save_settings_for_current_section_invoked', and the appropriate actions.
|
||||
*
|
||||
* @testWith ["wc_email_new_order", false]
|
||||
* ["", true]
|
||||
*
|
||||
* @param string $section_name The current section name.
|
||||
* @param bool $expect_save_settings_for_current_section Whether 'save_settings_for_current_section' is expected to be invoked or not.
|
||||
*/
|
||||
public function test_save_triggers_appropriate_methods_and_actions( $section_name, $expect_save_settings_for_current_section ) {
|
||||
global $current_section;
|
||||
$current_section = $section_name;
|
||||
|
||||
$save_settings_for_current_section_invoked = false;
|
||||
|
||||
$email = WC_Emails::instance()->get_emails()[ WC_Email_New_Order::class ];
|
||||
|
||||
$emails = $this->getMockBuilder( WC_Emails::class )
|
||||
->setMethods( array( 'get_emails' ) )
|
||||
->getMock();
|
||||
|
||||
$emails->method( 'get_emails' )
|
||||
->willReturn( array( WC_Email_New_Order::class => $email ) );
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Emails' => array(
|
||||
'instance' => function() use ( $emails ) {
|
||||
return $emails;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Emails::class )
|
||||
->setMethods( array( 'save_settings_for_current_section' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'save_settings_for_current_section' )
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function() use ( &$save_settings_for_current_section_invoked ) {
|
||||
$save_settings_for_current_section_invoked = true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$sut->save();
|
||||
|
||||
$this->assertEquals( $expect_save_settings_for_current_section, $save_settings_for_current_section_invoked );
|
||||
$this->assertEquals( '' === $section_name ? 0 : 1, did_action( 'woocommerce_update_options_email_new_order' ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Example file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper class to test base functionality of WC_Settings_Page.
|
||||
*/
|
||||
class WC_Settings_Example extends WC_Settings_Page {
|
||||
// phpcs:disable Squiz.Commenting.FunctionComment.Missing
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'example';
|
||||
$this->label = 'Example';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function get_settings_for_default_section() {
|
||||
return array( 'key' => 'value' );
|
||||
}
|
||||
|
||||
protected function get_settings_for_foobar_section() {
|
||||
return array( 'foo' => 'bar' );
|
||||
}
|
||||
|
||||
protected function get_settings_for_section_core( $section_id ) {
|
||||
return array( "${section_id}_key" => "${section_id}_value" );
|
||||
}
|
||||
|
||||
protected function get_own_sections() {
|
||||
$sections = parent::get_own_sections();
|
||||
$sections['new_section'] = 'New Section';
|
||||
return $sections;
|
||||
}
|
||||
|
||||
// phpcs:enable Squiz.Commenting.FunctionComment.Missing
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_General_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_General class.
|
||||
*/
|
||||
class WC_Settings_General_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test for get_settings (triggers the woocommerce_general_settings filter).
|
||||
*/
|
||||
public function test_get_settings__triggers_filter() {
|
||||
$actual_settings_via_filter = null;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_general_settings',
|
||||
function( $settings ) use ( &$actual_settings_via_filter ) {
|
||||
$actual_settings_via_filter = $settings;
|
||||
return $settings;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_General();
|
||||
|
||||
$actual_settings_returned = $sut->get_settings_for_section( '' );
|
||||
remove_all_filters( 'woocommerce_general_settings' );
|
||||
|
||||
$this->assertSame( $actual_settings_returned, $actual_settings_via_filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings (all settings are present).
|
||||
*/
|
||||
public function test_get_settings__all_settings_are_present() {
|
||||
$sut = new WC_Settings_General();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'woocommerce_store_address' => 'text',
|
||||
'woocommerce_store_address_2' => 'text',
|
||||
'woocommerce_store_city' => 'text',
|
||||
'woocommerce_default_country' => 'single_select_country',
|
||||
'woocommerce_store_postcode' => 'text',
|
||||
'store_address' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_allowed_countries' => 'select',
|
||||
'woocommerce_all_except_countries' => 'multi_select_countries',
|
||||
'woocommerce_specific_allowed_countries' => 'multi_select_countries',
|
||||
'woocommerce_ship_to_countries' => 'select',
|
||||
'woocommerce_specific_ship_to_countries' => 'multi_select_countries',
|
||||
'woocommerce_default_customer_address' => 'select',
|
||||
'woocommerce_calc_taxes' => 'checkbox',
|
||||
'woocommerce_enable_coupons' => 'checkbox',
|
||||
'woocommerce_calc_discounts_sequentially' => 'checkbox',
|
||||
'general_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_currency' => 'select',
|
||||
'woocommerce_currency_pos' => 'select',
|
||||
'woocommerce_price_thousand_sep' => 'text',
|
||||
'woocommerce_price_decimal_sep' => 'text',
|
||||
'woocommerce_price_num_decimals' => 'number',
|
||||
'pricing_options' => array( 'title', 'sectionend' ),
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings (retrieves currencies properly).
|
||||
*/
|
||||
public function test_get_settings__currencies() {
|
||||
FunctionsMockerHack::add_function_mocks(
|
||||
array(
|
||||
'get_woocommerce_currencies' => function() {
|
||||
return array(
|
||||
'c1' => 'Currency 1',
|
||||
'c2' => 'Currency 2',
|
||||
);
|
||||
},
|
||||
'get_woocommerce_currency_symbol' => function( $currency = '' ) {
|
||||
return "symbol for $currency";
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_General();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$currency_setting = $this->setting_by_id( $settings, 'woocommerce_currency' );
|
||||
$currencies = $currency_setting['options'];
|
||||
|
||||
$expected = array(
|
||||
'c1' => 'Currency 1 (symbol for c1)',
|
||||
'c2' => 'Currency 2 (symbol for c2)',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $currencies );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Integrations_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_Integration class.
|
||||
*/
|
||||
class WC_Settings_Integrations_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox 'get_sections' sets the current section to the id of the first integration if it's not set to anything.
|
||||
*/
|
||||
public function test_get_sections_sets_current_section_to_first_available_inegration_if_not_set() {
|
||||
global $current_section;
|
||||
|
||||
$integrations = array(
|
||||
(object) array(
|
||||
'id' => 'int_id',
|
||||
'method_title' => 'int_title',
|
||||
),
|
||||
);
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Integrations::class )
|
||||
->setMethods( array( 'get_integrations', 'wc_is_installing' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_integrations' )->willReturn( $integrations );
|
||||
$sut->method( 'wc_is_installing' )->willReturn( false );
|
||||
|
||||
$current_section = null;
|
||||
$sut->get_sections();
|
||||
|
||||
$this->assertEquals( 'int_id', $current_section );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox 'get_sections' returns a list of sections made from the ids and titles of the existing integrations.
|
||||
*/
|
||||
public function test_get_sections_returns_sections_made_from_existing_integrations() {
|
||||
$integrations = array(
|
||||
(object) array(
|
||||
'id' => 'int_1_id',
|
||||
'method_title' => null,
|
||||
),
|
||||
(object) array(
|
||||
'id' => 'int_2_id',
|
||||
'method_title' => 'int_2_title',
|
||||
),
|
||||
);
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Integrations::class )
|
||||
->setMethods( array( 'get_integrations', 'wc_is_installing' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_integrations' )->willReturn( $integrations );
|
||||
$sut->method( 'wc_is_installing' )->willReturn( false );
|
||||
|
||||
$sections = $sut->get_sections();
|
||||
|
||||
$expected_sections = array(
|
||||
'int_1_id' => 'Int_1_id',
|
||||
'int_2_id' => 'int_2_title',
|
||||
);
|
||||
$this->assertEquals( $expected_sections, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'output' invokes 'admin_options' in the integration whose id is equal to the current section name.
|
||||
*/
|
||||
public function test_output_invoked_admin_options_on_integration_pointed_by_current_section() {
|
||||
global $current_section;
|
||||
|
||||
$integrations = array(
|
||||
'int_id' =>
|
||||
new class() {
|
||||
//phpcs:disable Squiz.Commenting
|
||||
public $id;
|
||||
public $admin_options_invoked;
|
||||
|
||||
public function admin_options() {
|
||||
$this->admin_options_invoked = true;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'the_id';
|
||||
$this->admin_options_invoked = false;
|
||||
}
|
||||
//phpcs:enable
|
||||
},
|
||||
);
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Integrations::class )
|
||||
->setMethods( array( 'get_integrations' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_integrations' )->willReturn( $integrations );
|
||||
|
||||
$current_section = 'int_id';
|
||||
$sut->output();
|
||||
|
||||
$this->assertTrue( $integrations['int_id']->admin_options_invoked );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,335 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Page_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-example.php';
|
||||
require_once __DIR__ . '/class-wc-legacy-settings-example.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the base functionality of WC_Settings_Page.
|
||||
*/
|
||||
class WC_Settings_Page_Test extends WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test for constructor.
|
||||
*/
|
||||
public function test_constructor() {
|
||||
remove_all_filters( 'woocommerce_settings_tabs_array' );
|
||||
remove_all_filters( 'woocommerce_sections_example' );
|
||||
remove_all_filters( 'woocommerce_settings_example' );
|
||||
remove_all_filters( 'woocommerce_settings_save_example' );
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$this->assertTrue( has_filter( 'woocommerce_settings_tabs_array' ) );
|
||||
$this->assertTrue( has_filter( 'woocommerce_sections_example' ) );
|
||||
$this->assertTrue( has_filter( 'woocommerce_settings_example' ) );
|
||||
$this->assertTrue( has_filter( 'woocommerce_settings_save_example' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for add_settings_page.
|
||||
*/
|
||||
public function test_add_settings_page() {
|
||||
$pages = array( 'foo' => 'bar' );
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
$actual = $sut->add_settings_page( $pages );
|
||||
|
||||
$expected = array(
|
||||
'foo' => 'bar',
|
||||
'example' => 'Example',
|
||||
);
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings (default section).
|
||||
*/
|
||||
public function test_get_settings__default_section() {
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$actual = $sut->get_settings_for_section( '' );
|
||||
|
||||
$expected = array( 'key' => 'value' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings_for_section (default section).
|
||||
*/
|
||||
public function test_get_settings_for_section__default_section() {
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$actual = $sut->get_settings_for_section( '' );
|
||||
|
||||
$expected = array( 'key' => 'value' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings (named section with its own get_settings_for_X_section method).
|
||||
*/
|
||||
public function test_get_settings__named_section_with_own_method() {
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$actual = $sut->get_settings( 'foobar' );
|
||||
|
||||
$expected = array( 'foo' => 'bar' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings_for_section (named section with its own get_settings_for_X_section method).
|
||||
*/
|
||||
public function test_get_settings_for_section__named_section_with_own_method() {
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$actual = $sut->get_settings_for_section( 'foobar' );
|
||||
|
||||
$expected = array( 'foo' => 'bar' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings (named section without get_settings_for_X_section method).
|
||||
*/
|
||||
public function test_get_settings__named_section_without_own_method() {
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$actual = $sut->get_settings_for_section( 'fizzbuzz' );
|
||||
|
||||
$expected = array( 'fizzbuzz_key' => 'fizzbuzz_value' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_settings (triggers woocommerce_get_settings_X filter).
|
||||
*/
|
||||
public function test_get_settings__get_settings_filter() {
|
||||
$actual_settings = null;
|
||||
$actual_section = null;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_get_settings_example',
|
||||
function( $settings, $section ) use ( &$actual_settings, &$actual_section ) {
|
||||
$actual_settings = $settings;
|
||||
$actual_section = $section;
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
$sut->get_settings_for_section( 'foobar' );
|
||||
remove_all_filters( 'woocommerce_get_settings_example' );
|
||||
|
||||
$expected_section = 'foobar';
|
||||
$expected_settings = array( 'foo' => 'bar' );
|
||||
$this->assertEquals( $expected_section, $actual_section );
|
||||
$this->assertEquals( $expected_settings, $actual_settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_section (returned value).
|
||||
*/
|
||||
public function test_get_sections__result() {
|
||||
$sut = new WC_Settings_Example();
|
||||
$actual = $sut->get_sections();
|
||||
|
||||
$expected = array(
|
||||
'' => 'General',
|
||||
'new_section' => 'New Section',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_section (triggers the woocommerce_get_sections_X filter).
|
||||
*/
|
||||
public function test_get_sections__get_sections_filter() {
|
||||
$actual_sections = null;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_get_sections_example',
|
||||
function( $sections ) use ( &$actual_sections ) {
|
||||
$actual_sections = $sections;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
$sut->get_sections();
|
||||
remove_all_filters( 'woocommerce_get_sections_example' );
|
||||
|
||||
$expected_sections = array(
|
||||
'' => 'General',
|
||||
'new_section' => 'New Section',
|
||||
);
|
||||
$this->assertEquals( $expected_sections, $actual_sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for output_sections.
|
||||
*/
|
||||
public function test_output_sections() {
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$expected = <<<'HTML'
|
||||
<ul class="subsubsub">
|
||||
<li>
|
||||
<a href="http://example.org/wp-admin/admin.php?page=wc-settings&tab=example§ion=" class="">General</a> | </li>
|
||||
<li>
|
||||
<a href="http://example.org/wp-admin/admin.php?page=wc-settings&tab=example§ion=new_section" class="">New Section</a></li>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
HTML;
|
||||
|
||||
$this->assertOutputsHTML( $expected, array( $sut, 'output_sections' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for output.
|
||||
*/
|
||||
public function test_output() {
|
||||
global $current_section;
|
||||
|
||||
$actual = null;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Settings' => array(
|
||||
'output_fields' => function( $settings ) use ( &$actual ) {
|
||||
$actual = $settings;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$current_section = 'foobar';
|
||||
$sut->output();
|
||||
|
||||
$expected = array( 'foo' => 'bar' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for output on a legacy settings class.
|
||||
*/
|
||||
public function test_output_on_legacy_class() {
|
||||
global $current_section;
|
||||
|
||||
$actual = null;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Settings' => array(
|
||||
'output_fields' => function( $settings ) use ( &$actual ) {
|
||||
$actual = $settings;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Legacy_Settings_Example();
|
||||
|
||||
$current_section = 'foobar';
|
||||
$sut->output();
|
||||
|
||||
$expected = array( 'foo' => 'bar' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for save (invokes the save_fields method).
|
||||
*/
|
||||
public function test_save__saves_fields() {
|
||||
global $current_section;
|
||||
|
||||
$actual = null;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Settings' => array(
|
||||
'save_fields' => function( $settings ) use ( &$actual ) {
|
||||
$actual = $settings;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
|
||||
$current_section = 'foobar';
|
||||
$sut->save();
|
||||
|
||||
$expected = array( 'foo' => 'bar' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for save (invokes the save_fields method) on a legacy settings class.
|
||||
*/
|
||||
public function test_save_on_legacy_class__saves_fields() {
|
||||
global $current_section;
|
||||
|
||||
$actual = null;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Settings' => array(
|
||||
'save_fields' => function( $settings ) use ( &$actual ) {
|
||||
$actual = $settings;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Legacy_Settings_Example();
|
||||
|
||||
$current_section = 'foobar';
|
||||
$sut->save();
|
||||
|
||||
$expected = array( 'foo' => 'bar' );
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for save (named section, triggers the woocommerce_update_options_example_foobar action).
|
||||
*/
|
||||
public function test_save__does_update_options_action__named_section() {
|
||||
global $current_section;
|
||||
|
||||
$current_section = 'foobar';
|
||||
remove_all_filters( 'woocommerce_update_options_example_foobar' );
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
$sut->save();
|
||||
|
||||
$this->assertEquals( 1, did_action( 'woocommerce_update_options_example_foobar' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for save (default section, doesn't trigger any woocommerce_update_options_ action).
|
||||
*/
|
||||
public function test_save__does_update_options_action__default_section() {
|
||||
global $current_section;
|
||||
|
||||
$current_section = '';
|
||||
remove_all_filters( 'woocommerce_update_options_example_' );
|
||||
|
||||
$sut = new WC_Settings_Example();
|
||||
$sut->save();
|
||||
|
||||
$this->assertEquals( 0, did_action( 'woocommerce_update_options_example_' ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Payment_Gateways_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_Payment_Gateways class.
|
||||
*/
|
||||
class WC_Settings_Payment_Gateways_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox get_sections should get all the existing sections.
|
||||
*/
|
||||
public function test_get_sections() {
|
||||
$sut = new WC_Settings_Payment_Gateways();
|
||||
|
||||
$section_names = array_keys( $sut->get_sections() );
|
||||
|
||||
$expected = array(
|
||||
'',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $section_names );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_settings should trigger the appropriate filter depending on the requested section name.
|
||||
*
|
||||
* @testWith ["", "woocommerce_payment_gateways_settings"]
|
||||
* ["woocommerce_com", "woocommerce_get_settings_checkout"]
|
||||
*
|
||||
* @param string $section_name The section name to test getting the settings for.
|
||||
* @param string $filter_name The name of the filter that is expected to be triggered.
|
||||
*/
|
||||
public function test_get_settings_triggers_filter( $section_name, $filter_name ) {
|
||||
$actual_settings_via_filter = null;
|
||||
|
||||
add_filter(
|
||||
$filter_name,
|
||||
function ( $settings ) use ( &$actual_settings_via_filter ) {
|
||||
$actual_settings_via_filter = $settings;
|
||||
|
||||
return $settings;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Payment_Gateways();
|
||||
|
||||
$actual_settings_returned = $sut->get_settings_for_section( $section_name );
|
||||
remove_all_filters( $filter_name );
|
||||
|
||||
$this->assertSame( $actual_settings_returned, $actual_settings_via_filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('') should return all the settings for the default section.
|
||||
*/
|
||||
public function test_get_default_settings_returns_all_settings() {
|
||||
$sut = new WC_Settings_Payment_Gateways();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'payment_gateways_options' => array( 'title', 'sectionend' ),
|
||||
'' => 'payment_gateways',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox When the current section is the name of an existing gateway, 'output' invokes that gateway's 'admin_options' method.
|
||||
*
|
||||
* @testWith ["bacs"]
|
||||
* ["wc_gateway_bacs"]
|
||||
*
|
||||
* @param string $section_name The name of the current section.
|
||||
*/
|
||||
public function test_output_is_done_via_admin_options_method_of_gateway_specified_as_settings_section( $section_name ) {
|
||||
global $current_section;
|
||||
$current_section = $section_name;
|
||||
|
||||
$admin_options_invoked = false;
|
||||
$actual_gateway = null;
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Payment_Gateways::class )
|
||||
->setMethods( array( 'run_gateway_admin_options' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'run_gateway_admin_options' )
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function( $gateway ) use ( &$admin_options_invoked, &$actual_gateway ) {
|
||||
$admin_options_invoked = true;
|
||||
$actual_gateway = $gateway;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertTrue( $admin_options_invoked );
|
||||
$this->assertInstanceOf( WC_Gateway_BACS::class, $actual_gateway );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'save' will trigger 'init' (and 'process_admin_options' if current section is the name of an existing gateway), and the appropriate actions.
|
||||
*
|
||||
* @testWith ["bacs", false]
|
||||
* ["wc_gateway_bacs", false]
|
||||
* ["", true]
|
||||
*
|
||||
* @param string $section_name The current section name.
|
||||
* @param bool $expect_to_run_process_admin_options Whether 'admin_options' is expected to be invoked in WC_Payment_Gateways or not.
|
||||
*/
|
||||
public function test_save_triggers_appropriate_gateway_methods_and_actions( $section_name, $expect_to_run_process_admin_options ) {
|
||||
global $current_section;
|
||||
$current_section = $section_name;
|
||||
|
||||
$process_admin_options_invoked = false;
|
||||
$init_invoked = false;
|
||||
|
||||
$gateway = WC_Payment_Gateways::instance()->payment_gateways()['bacs'];
|
||||
|
||||
$payment_gateways = $this->getMockBuilder( WC_Payment_Gateways::class )
|
||||
->setMethods( array( 'process_admin_options', 'init', 'payment_gateways' ) )
|
||||
->getMock();
|
||||
|
||||
$payment_gateways->method( 'process_admin_options' )
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function() use ( &$process_admin_options_invoked ) {
|
||||
$process_admin_options_invoked = true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$payment_gateways->method( 'init' )
|
||||
->will(
|
||||
$this->returnCallback(
|
||||
function() use ( &$init_invoked ) {
|
||||
$init_invoked = true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$payment_gateways->method( 'payment_gateways' )
|
||||
->willReturn( array( $gateway ) );
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Payment_Gateways' => array(
|
||||
'instance' => function() use ( $payment_gateways ) {
|
||||
return $payment_gateways;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Payment_Gateways();
|
||||
$sut->save();
|
||||
|
||||
$this->assertTrue( $init_invoked );
|
||||
$this->assertEquals( $expect_to_run_process_admin_options, $process_admin_options_invoked );
|
||||
|
||||
$this->assertEquals( '' === $section_name ? 0 : 1, did_action( 'woocommerce_update_options_payment_gateways_bacs' ) );
|
||||
$this->assertEquals( '' === $section_name ? 0 : 1, did_action( 'woocommerce_update_options_checkout_' . $section_name ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Products_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
// phpcs:ignore Squiz.Commenting.FileComment.Missing
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_Products class.
|
||||
*/
|
||||
class WC_Settings_Products_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox get_sections should get all the existing sections.
|
||||
*/
|
||||
public function test_get_sections() {
|
||||
$sut = new WC_Settings_Products();
|
||||
|
||||
$section_names = array_keys( $sut->get_sections() );
|
||||
|
||||
$expected = array(
|
||||
'',
|
||||
'inventory',
|
||||
'downloadable',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $section_names );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_settings should trigger the appropriate filter(s) depending on the requested section name.
|
||||
*
|
||||
* @testWith ["", ["woocommerce_products_general_settings", "woocommerce_product_settings"]]
|
||||
* ["inventory", ["woocommerce_inventory_settings"]]
|
||||
* ["downloadable", ["woocommerce_downloadable_products_settings"]]
|
||||
*
|
||||
* @param string $section_name The section name to test getting the settings for.
|
||||
* @param string $filter_names The name of the filter that is expected to be triggered.
|
||||
*/
|
||||
public function test_get_settings_triggers_filter( $section_name, $filter_names ) {
|
||||
$actual_settings_via_filter = array();
|
||||
|
||||
foreach ( $filter_names as $filter_name ) {
|
||||
add_filter(
|
||||
$filter_name,
|
||||
function ( $settings ) use ( $filter_name, &$actual_settings_via_filter ) {
|
||||
$actual_settings_via_filter[ $filter_name ] = $settings;
|
||||
|
||||
return $settings;
|
||||
},
|
||||
10,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
$sut = new WC_Settings_Products();
|
||||
|
||||
$actual_settings_returned = $sut->get_settings_for_section( $section_name );
|
||||
|
||||
foreach ( $filter_names as $filter_name ) {
|
||||
remove_all_filters( $filter_name );
|
||||
}
|
||||
|
||||
foreach ( $filter_names as $filter_name ) {
|
||||
$this->assertSame( $actual_settings_returned, $actual_settings_via_filter[ $filter_name ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('') should return all the settings for the default section.
|
||||
*/
|
||||
public function test_get_default_settings_returns_all_settings() {
|
||||
$sut = new WC_Settings_Products();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'catalog_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_shop_page_id' => 'single_select_page',
|
||||
'woocommerce_cart_redirect_after_add' => 'checkbox',
|
||||
'woocommerce_enable_ajax_add_to_cart' => 'checkbox',
|
||||
'woocommerce_placeholder_image' => 'text',
|
||||
'product_measurement_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_weight_unit' => 'select',
|
||||
'woocommerce_dimension_unit' => 'select',
|
||||
'product_rating_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_enable_reviews' => 'checkbox',
|
||||
'woocommerce_review_rating_verification_label' => 'checkbox',
|
||||
'woocommerce_review_rating_verification_required' => 'checkbox',
|
||||
'woocommerce_enable_review_rating' => 'checkbox',
|
||||
'woocommerce_review_rating_required' => 'checkbox',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('inventory') should return all the settings for the inventory section.
|
||||
*/
|
||||
public function test_get_inventory_settings_returns_all_settings() {
|
||||
$sut = new WC_Settings_Products();
|
||||
|
||||
$settings = $sut->get_settings_for_section( 'inventory' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'product_inventory_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_manage_stock' => 'checkbox',
|
||||
'woocommerce_hold_stock_minutes' => 'number',
|
||||
'woocommerce_notify_low_stock' => 'checkbox',
|
||||
'woocommerce_notify_no_stock' => 'checkbox',
|
||||
'woocommerce_stock_email_recipient' => 'text',
|
||||
'woocommerce_notify_low_stock_amount' => 'number',
|
||||
'woocommerce_notify_no_stock_amount' => 'number',
|
||||
'woocommerce_hide_out_of_stock_items' => 'checkbox',
|
||||
'woocommerce_stock_format' => 'select',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox get_settings('downloadable') should return all the settings for the inventory section.
|
||||
*/
|
||||
public function test_get_downloadable_settings_returns_all_settings() {
|
||||
$sut = new WC_Settings_Products();
|
||||
|
||||
$settings = $sut->get_settings_for_section( 'downloadable' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'digital_download_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_file_download_method' => 'select',
|
||||
'woocommerce_downloads_require_login' => 'checkbox',
|
||||
'woocommerce_downloads_grant_access_after_payment' => 'checkbox',
|
||||
'woocommerce_downloads_add_hash_to_filename' => 'checkbox',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox 'save' flushes the term count cache.
|
||||
*/
|
||||
public function test_save_does_recount_terms() {
|
||||
$wc_recount_all_terms_called = false;
|
||||
|
||||
$this->register_legacy_proxy_function_mocks(
|
||||
array(
|
||||
'wc_recount_all_terms' => function() use ( &$wc_recount_all_terms_called ) {
|
||||
$wc_recount_all_terms_called = true;
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Products();
|
||||
$sut->save();
|
||||
|
||||
$this->assertTrue( $wc_recount_all_terms_called );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,317 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Shipping_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_Shipping class.
|
||||
*/
|
||||
class WC_Settings_Shipping_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testDox 'get_sections' returns a fixed set of sections, plus one section for each shipping method having settings.
|
||||
*/
|
||||
public function test_get_sections_returns_fixed_sections_and_one_section_per_shipping_method_with_settings() {
|
||||
$methods = array(
|
||||
//phpcs:disable Squiz.Commenting
|
||||
new class() {
|
||||
public $id;
|
||||
public $method_title;
|
||||
|
||||
public function has_settings() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'method_with_no_settings';
|
||||
}
|
||||
},
|
||||
new class() {
|
||||
public $id;
|
||||
public $method_title;
|
||||
|
||||
public function has_settings() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'method_1_id';
|
||||
$this->method_title = null;
|
||||
}
|
||||
},
|
||||
new class() {
|
||||
public $id;
|
||||
public $method_title;
|
||||
|
||||
public function has_settings() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'method_2_id';
|
||||
$this->method_title = 'method_2_title';
|
||||
}
|
||||
},
|
||||
//phpcs:enable
|
||||
);
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Shipping::class )
|
||||
->setMethods( array( 'get_shipping_methods', 'wc_is_installing' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_shipping_methods' )->willReturn( $methods );
|
||||
$sut->method( 'wc_is_installing' )->willReturn( false );
|
||||
|
||||
$sections = $sut->get_sections();
|
||||
|
||||
$expected = array(
|
||||
'' => 'Shipping zones',
|
||||
'options' => 'Shipping options',
|
||||
'classes' => 'Shipping classes',
|
||||
'method_1_id' => 'Method_1_id',
|
||||
'method_2_id' => 'method_2_title',
|
||||
);
|
||||
$this->assertEquals( $expected, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'get_settings' returns proper default settings, also 'options' is an alias for the default section.
|
||||
*
|
||||
* @testWith [""]
|
||||
* ["options"]
|
||||
*
|
||||
* @param string $section_name The name of the section to get the settings for.
|
||||
*/
|
||||
public function test_get_default_and_options_settings_returns_all_settings( $section_name ) {
|
||||
$sut = new WC_Settings_Shipping();
|
||||
|
||||
$settings = $sut->get_settings_for_section( $section_name );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'shipping_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_enable_shipping_calc' => 'checkbox',
|
||||
'woocommerce_shipping_cost_requires_address' => 'checkbox',
|
||||
'woocommerce_ship_to_destination' => 'radio',
|
||||
'woocommerce_shipping_debug_mode' => 'checkbox',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'output' for a predefined section invokes the appropriate internal method.
|
||||
*
|
||||
* @testWith ["", "output_zones_screen"]
|
||||
* ["classes", "output_shipping_class_screen"]
|
||||
*
|
||||
* @param string $section_name Current section name.
|
||||
* @param string $expected_method_invoked Name of the internal method expected to be invoked.
|
||||
*/
|
||||
public function test_output_for_predefined_section( $section_name, $expected_method_invoked ) {
|
||||
global $current_section;
|
||||
$current_section = $section_name;
|
||||
|
||||
$method_invoked = null;
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Shipping::class )
|
||||
->setMethods( array( 'get_shipping_methods', 'output_zones_screen', 'output_fields', 'output_shipping_class_screen' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_shipping_methods' )->willReturn( array() );
|
||||
$sut->method( 'output_zones_screen' )->will(
|
||||
$this->returnCallback(
|
||||
function() use ( &$method_invoked ) {
|
||||
$method_invoked = 'output_zones_screen';
|
||||
}
|
||||
)
|
||||
);
|
||||
$sut->method( 'output_shipping_class_screen' )->will(
|
||||
$this->returnCallback(
|
||||
function() use ( &$method_invoked ) {
|
||||
$method_invoked = 'output_shipping_class_screen';
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertEquals( $expected_method_invoked, $method_invoked );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'output' invokes 'admin_options' of the method if section is the id of a shipping method with settings.
|
||||
*/
|
||||
public function test_output_for_shipping_method_id_with_settings() {
|
||||
global $current_section;
|
||||
$current_section = 'method_id';
|
||||
|
||||
//phpcs:disable Squiz.Commenting
|
||||
$method =
|
||||
new class() {
|
||||
public $id;
|
||||
public $method_title;
|
||||
public $admin_options_invoked;
|
||||
|
||||
public function has_settings() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function admin_options() {
|
||||
$this->admin_options_invoked = true;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'method_id';
|
||||
$this->admin_options_invoked = false;
|
||||
}
|
||||
};
|
||||
//phpcs:enable
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Shipping::class )
|
||||
->setMethods( array( 'get_shipping_methods' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_shipping_methods' )->willReturn( array( $method ) );
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertTrue( $method->admin_options_invoked );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'output' fallbacks to default behavior when section is for a shipping method without settings, or not a known shipping method.
|
||||
*
|
||||
* @testWith ["method_name"]
|
||||
* ["foobar"]
|
||||
*
|
||||
* @param string $section_name Current section name.
|
||||
*/
|
||||
public function test_output_for_shipping_method_without_settings_or_unknown_section( $section_name ) {
|
||||
global $current_section;
|
||||
$current_section = $section_name;
|
||||
|
||||
$output_fields_in_admin_settings_invoked = false;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Settings' => array(
|
||||
'output_fields' => function( $settings ) use ( &$output_fields_in_admin_settings_invoked ) {
|
||||
$output_fields_in_admin_settings_invoked = true;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
//phpcs:disable Squiz.Commenting
|
||||
$method =
|
||||
new class() {
|
||||
public $id;
|
||||
public $method_title;
|
||||
public $admin_options_invoked;
|
||||
|
||||
public function has_settings() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function admin_options() {
|
||||
$this->admin_options_invoked = true;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'method_id';
|
||||
$this->admin_options_invoked = false;
|
||||
}
|
||||
};
|
||||
//phpcs:enable
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Shipping::class )
|
||||
->setMethods( array( 'get_shipping_methods' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_shipping_methods' )->willReturn( array( $method ) );
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertFalse( $method->admin_options_invoked );
|
||||
$this->assertTrue( $output_fields_in_admin_settings_invoked );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'save' triggers the appropriate action, and also 'save_settings_for_current_section' if needed, when the current section is a predefined one.
|
||||
*
|
||||
* @testWith ["", false, false]
|
||||
* ["options", true, true]
|
||||
* ["classes", false, true]
|
||||
*
|
||||
* @param string $section_name Current section name.
|
||||
* @param bool $expect_save_settings_for_current_section_invoked Is 'save_settings_for_current_section' expected to be invoked?.
|
||||
* @param bool $expect_update_options_action_invoked Is the 'woocommerce_update_options_' action expected to be triggered?.
|
||||
*/
|
||||
public function test_save_predefined_section( $section_name, $expect_save_settings_for_current_section_invoked, $expect_update_options_action_invoked ) {
|
||||
global $current_section;
|
||||
$current_section = $section_name;
|
||||
|
||||
$save_settings_for_current_section_invoked = false;
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Shipping::class )
|
||||
->setMethods( array( 'get_shipping_methods', 'save_settings_for_current_section' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_shipping_methods' )->willReturn( array() );
|
||||
$sut->method( 'save_settings_for_current_section' )->will(
|
||||
$this->returnCallback(
|
||||
function() use ( &$save_settings_for_current_section_invoked ) {
|
||||
$save_settings_for_current_section_invoked = true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$sut->save();
|
||||
|
||||
$this->assertEquals( $expect_save_settings_for_current_section_invoked, $save_settings_for_current_section_invoked );
|
||||
$this->assertEquals( $expect_update_options_action_invoked ? 1 : 0, did_action( 'woocommerce_update_options_shipping_' . $section_name ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'save' triggers 'woocommerce_update_options_shipping_{method_id}' when the current section is the id of a shipping method with settings.
|
||||
*/
|
||||
public function test_save_for_shipping_method_triggers_appropriate_action() {
|
||||
global $current_section;
|
||||
$current_section = 'method_id';
|
||||
|
||||
//phpcs:disable Squiz.Commenting
|
||||
$method =
|
||||
new class() {
|
||||
public $id;
|
||||
public $method_title;
|
||||
public $admin_options_invoked;
|
||||
|
||||
public function has_settings() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 'method_id';
|
||||
}
|
||||
};
|
||||
//phpcs:enable
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Shipping::class )
|
||||
->setMethods( array( 'get_shipping_methods' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'get_shipping_methods' )->willReturn( array( $method ) );
|
||||
|
||||
$sut->save();
|
||||
|
||||
$this->assertEquals( 1, did_action( 'woocommerce_update_options_shipping_method_id' ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Tax_Test file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\FunctionsMockerHack;
|
||||
use Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks\StaticMockerHack;
|
||||
|
||||
require_once __DIR__ . '/class-wc-settings-unit-test-case.php';
|
||||
|
||||
/**
|
||||
* Unit tests for the WC_Settings_Tax class.
|
||||
*/
|
||||
class WC_Settings_Tax_Test extends WC_Settings_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testDox 'get_sections' returns the predefined sections as well as one section per existing tax class.
|
||||
*/
|
||||
public function test_get_sections_returns_predefined_sections_and_one_section_per_tax_class() {
|
||||
$tax_classes = array( 'tax_class_1', 'tax_class_2' );
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
WC_Tax::class => array(
|
||||
'get_tax_classes' => function() use ( $tax_classes ) {
|
||||
return $tax_classes;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Tax();
|
||||
$sections = $sut->get_sections();
|
||||
|
||||
$expected = array(
|
||||
'' => 'Tax options',
|
||||
'standard' => 'Standard rates',
|
||||
'tax_class_1' => 'tax_class_1 rates',
|
||||
'tax_class_2' => 'tax_class_2 rates',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $sections );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'get_settings' returns the appropriate settings for the default section.
|
||||
*/
|
||||
public function test_get_settings_for_default_section() {
|
||||
$sut = new WC_Settings_Tax();
|
||||
|
||||
$settings = $sut->get_settings_for_section( '' );
|
||||
$settings_ids_and_types = $this->get_ids_and_types( $settings );
|
||||
|
||||
$expected = array(
|
||||
'tax_options' => array( 'title', 'sectionend' ),
|
||||
'woocommerce_prices_include_tax' => 'radio',
|
||||
'woocommerce_tax_based_on' => 'select',
|
||||
'woocommerce_shipping_tax_class' => 'select',
|
||||
'woocommerce_tax_round_at_subtotal' => 'checkbox',
|
||||
'woocommerce_tax_classes' => 'textarea',
|
||||
'woocommerce_tax_display_shop' => 'select',
|
||||
'woocommerce_tax_display_cart' => 'select',
|
||||
'woocommerce_price_display_suffix' => 'text',
|
||||
'woocommerce_tax_total_display' => 'select',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $settings_ids_and_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'output' invokes 'output_tax_rates' for the 'standard' section and for sections named as a tax class.
|
||||
*
|
||||
* @testWith ["standard"]
|
||||
* ["tax_class_slug"]
|
||||
*
|
||||
* @param string $section_name Current section name.
|
||||
*/
|
||||
public function test_output_for_standard_section_and_known_tax_class( $section_name ) {
|
||||
global $current_section;
|
||||
$current_section = $section_name;
|
||||
|
||||
$output_tax_rates_invoked = false;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Tax' => array(
|
||||
'get_tax_class_slugs' => function() {
|
||||
return array( 'tax_class_slug' );
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = $this->getMockBuilder( WC_Settings_Tax::class )
|
||||
->setMethods( array( 'output_tax_rates' ) )
|
||||
->getMock();
|
||||
|
||||
$sut->method( 'output_tax_rates' )->will(
|
||||
$this->returnCallback(
|
||||
function() use ( &$output_tax_rates_invoked ) {
|
||||
$output_tax_rates_invoked = true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertTrue( $output_tax_rates_invoked );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'output' fallbacks to 'output_fields' in WC_Admin_Settings for an unknown tax class.
|
||||
*/
|
||||
public function test_output_for_unknown_tax_class() {
|
||||
global $current_section;
|
||||
$current_section = 'foobar';
|
||||
|
||||
$output_fields_in_admin_settings_invoked = false;
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Admin_Settings' => array(
|
||||
'output_fields' => function( $settings ) use ( &$output_fields_in_admin_settings_invoked ) {
|
||||
$output_fields_in_admin_settings_invoked = true;
|
||||
},
|
||||
),
|
||||
'WC_Tax' => array(
|
||||
'get_tax_class_slugs' => function() {
|
||||
return array( 'tax_class_slug' );
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Tax();
|
||||
|
||||
$sut->output();
|
||||
|
||||
$this->assertTrue( $output_fields_in_admin_settings_invoked );
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox 'save_tax_classes' appropriately creates or deletes the tax classes.
|
||||
*/
|
||||
public function test_save_tax_classes() {
|
||||
$created = array();
|
||||
$deleted = array();
|
||||
|
||||
StaticMockerHack::add_method_mocks(
|
||||
array(
|
||||
'WC_Tax' => array(
|
||||
'get_tax_classes' => function() {
|
||||
return array( 'tax_1', 'tax_2', 'tax_3' );
|
||||
},
|
||||
'delete_tax_class_by' => function( $field, $name ) use ( &$deleted ) {
|
||||
$deleted[] = $name;
|
||||
},
|
||||
'create_tax_class' => function( $name ) use ( &$created ) {
|
||||
$created[] = $name;
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sut = new WC_Settings_Tax();
|
||||
|
||||
$sut->save_tax_classes( "tax_2\ntax_3\ntax_4" );
|
||||
|
||||
$this->assertEquals( array( 'tax_1' ), $deleted );
|
||||
$this->assertEquals( array( 'tax_4' ), $created );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_Settings_Unit_Test_Case file.
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for settings related unit tests.
|
||||
*/
|
||||
abstract class WC_Settings_Unit_Test_Case extends WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Given a settings array return the one having the given identifier.
|
||||
*
|
||||
* @param array $settings Settings array.
|
||||
* @param string $id Identifier to find for.
|
||||
*
|
||||
* @return array|null The setting, or null if no setting exists in the supplied array with the supplied identifier.
|
||||
*/
|
||||
public function setting_by_id( $settings, $id ) {
|
||||
foreach ( $settings as $setting ) {
|
||||
if ( $id === $setting['id'] ) {
|
||||
return $setting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a settings array return an associative array of id => type.
|
||||
* If more than one setting has the same id then the returned array is id => array of types.
|
||||
*
|
||||
* @param array $settings The settings to transform.
|
||||
*
|
||||
* @return array The transformed settings.
|
||||
*/
|
||||
public function get_ids_and_types( $settings ) {
|
||||
$settings_ids_and_types = array();
|
||||
foreach ( $settings as $setting ) {
|
||||
$id = array_key_exists( 'id', $setting ) ? $setting['id'] : null;
|
||||
$type = $setting['type'];
|
||||
if ( ! array_key_exists( $id, $settings_ids_and_types ) ) {
|
||||
$settings_ids_and_types[ $id ] = $type;
|
||||
} elseif ( is_array( $settings_ids_and_types[ $id ] ) ) {
|
||||
$settings_ids_and_types[ $id ][] = $type;
|
||||
} else {
|
||||
$settings_ids_and_types[ $id ] = array( $settings_ids_and_types[ $id ], $type );
|
||||
}
|
||||
}
|
||||
|
||||
return $settings_ids_and_types;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue