Wp wc (WP-CLI)
wp wc: Commando's voor interactie met WooCommerce.
Belangrijkste bronnen:
$ wp help wc NAME wp wc SYNOPSIS wp wc <command> SUBCOMMANDS customer customer_download order_note payment_gateway product product_attribute product_attribute_term product_cat product_review product_shipping_class product_tag product_variation shipping_method shipping_zone shipping_zone_location shipping_zone_method shop_coupon shop_order shop_order_refund tax tax_class tool tracker update Runs all pending WooCommerce database updates. webhook webhook_delivery
Reporting
Er lijken geen commando's te zijn voor reporting, maar er is hoop:
wp wc customer
wp wc customer_download
wp wc order_note
wp wc payment_gateway
wp wc product
wp help wc product
:
NAME wp wc product SYNOPSIS wp wc product <command> SUBCOMMANDS create Create a new item. delete Delete an existing item. get Get a single item. list List all items. update Update an existing item.
wp wc product create
Zie wp wc product create (WP-CLI).
wp wc product list
Bekijk alle productgegevens:
$wp wc product list NAME wp wc product list DESCRIPTION List all items. SYNOPSIS wp wc product list [--context=<context>] [--page=<page>] [--per_page=<per_page>] [--search=<search>] [--after=<after>] [--before=<before>] [--dates_are_gmt=<dates_are_gmt>] [--exclude=<exclude>] [--include=<include>] [--offset=<offset>] [--order=<order>] [--orderby=<orderby>] [--parent=<parent>] [--parent_exclude=<parent_exclude>] [--slug=<slug>] [--status=<status>] [--type=<type>] [--sku=<sku>] [--featured=<featured>] [--category=<category>] [--tag=<tag>] [--shipping_class=<shipping_class>] [--attribute=<attribute>] [--attribute_term=<attribute_term>] [--tax_class=<tax_class>] [--in_stock=<in_stock>] [--on_sale=<on_sale>] [--min_price=<min_price>] [--max_price=<max_price>] [--fields=<fields>] [--field=<field>] [--format=<format>] OPTIONS [--context=<context>] Scope under which the request is made; determines fields present in response. [--page=<page>] Current page of the collection. [--per_page=<per_page>] Maximum number of items to be returned in result set. [--search=<search>] Limit results to those matching a string. [--after=<after>] Limit response to resources published after a given ISO8601 compliant date. [--before=<before>] Limit response to resources published before a given ISO8601 compliant date. [--dates_are_gmt=<dates_are_gmt>] Whether to use GMT post dates. [--exclude=<exclude>] Ensure result set excludes specific IDs. [--include=<include>] Limit result set to specific ids. [--offset=<offset>] Offset the result set by a specific number of items. [--order=<order>] Order sort attribute ascending or descending. [--orderby=<orderby>] Sort collection by object attribute. [--parent=<parent>] Limit result set to those of particular parent IDs. [--parent_exclude=<parent_exclude>] Limit result set to all items except those of a particular parent ID. [--slug=<slug>] Limit result set to products with a specific slug. [--status=<status>] Limit result set to products assigned a specific status. [--type=<type>] Limit result set to products assigned a specific type. [--sku=<sku>] Limit result set to products with specific SKU(s). Use commas to separate. [--featured=<featured>] Limit result set to featured products. [--category=<category>] Limit result set to products assigned a specific category ID. [--tag=<tag>] Limit result set to products assigned a specific tag ID. [--shipping_class=<shipping_class>] Limit result set to products assigned a specific shipping class ID. [--attribute=<attribute>] Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug. [--attribute_term=<attribute_term>] Limit result set to products with a specific attribute term ID (required an assigned attribute). [--tax_class=<tax_class>] Limit result set to products with a specific tax class. [--in_stock=<in_stock>] Limit result set to products in stock or out of stock. [--on_sale=<on_sale>] Limit result set to products on sale. [--min_price=<min_price>] Limit result set to products based on a minimum price. [--max_price=<max_price>] Limit result set to products based on a maximum price. [--fields=<fields>] Limit response to specific fields. Defaults to all fields. [--field=<field>] Get the value of an individual field. [--format=<format>] Render response in a particular format. --- default: table options: - table - json - csv - ids - yaml - count - headers - body - envelope ---
Overkill
Op 2 aug. 2021 kreeg ik de output van maar liefst 65 velden. Sommige hiervan zijn vermoedelijk maatwerk en soms was de output serialised:
|
|
|
|
|
Dit is niet te doen via de terminal. Het is wel goed te doen door de output in csv-format te redirecten naar een bestand en daarna te openen met Calc. Bv. via wp wc product --user=4 list --per_page=5 --format="csv" > prod1.csv
.
Het goede nieuws: Tijdens klonen-&-vertalen in aug. 2021, had ik slechts deze velden nodig:
- name
- description
- short_description.
Daarnaast zijn er nog een aantal maatwerkvelden. Die zijn serialised ondergebracht in het laatste veld meta_data. Daarvan waren de volgende velden relevant zijn qua vertaalwerk:
- post_tools
- _yoast_wpseo_focuskw
- _yoast_wpseo_metadesc
- _yoast_wpseo_title
Hoeveel producten?
Hoeveel producten zitten er in de webwinkel?
Voorbeeld:
$ wp wc product --user=4 list --format="count" 16972
wp wc product_attribute
$ wp wc product_attribute usage: wp wc product_attribute create --name=<name> [--slug=<slug>] [--type=<type>] [--order_by=<order_by>] [--has_archives=<has_archives>] [--porcelain] or: wp wc product_attribute delete <id> [--id=<id>] [--force=<force>] [--porcelain] or: wp wc product_attribute get <id> [--id=<id>] [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>] or: wp wc product_attribute list [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>] or: wp wc product_attribute update <id> [--id=<id>] [--name=<name>] [--slug=<slug>] [--type=<type>] [--order_by=<order_by>] [--has_archives=<has_archives>] [--porcelain] See 'wp help wc product_attribute <command>' for more information on a specific command.
wp wc product_attribute create
wp wc product_attribute delete
$ wp help wc product_attribute delete NAME wp wc product_attribute delete DESCRIPTION Delete an existing item. SYNOPSIS wp wc product_attribute delete <id> [--id=<id>] [--force=<force>] [--porcelain] OPTIONS <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--force=<force>] Required to be true, as resource does not support trashing. [--porcelain] Output just the id when the operation is successful.
wp wc product_attribute get
Zie voorbeeld hieronder voor context. Voorbeeld:
$ wp wc product_attribute get 29 --user=4 +--------------+-------------+ | Field | Value | +--------------+-------------+ | id | 29 | | name | Apparaat | | slug | pa_apparaat | | type | select | | order_by | menu_order | | has_archives | true | +--------------+-------------+
wp wc product_attribute list
Vraag een lijst op van attribute taxonomies.
$ wp help wc product_attribute list NAME wp wc product_attribute list DESCRIPTION List all items. SYNOPSIS wp wc product_attribute list [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>] OPTIONS [--context=<context>] Scope under which the request is made; determines fields present in response. [--fields=<fields>] Limit response to specific fields. Defaults to all fields. [--field=<field>] Get the value of an individual field. [--format=<format>] Render response in a particular format. --- default: table options: - table - json - csv - ids - yaml - count - headers - body - envelope ---
Voorbeeld:
$ wp --user=4 wc product_attribute list +----+-----------------------+--------------------------+--------+------------+--------------+ | id | name | slug | type | order_by | has_archives | +----+-----------------------+--------------------------+--------+------------+--------------+ | 29 | Apparaat | pa_apparaat | select | menu_order | 1 | | 16 | As-code | pa_as_code | select | menu_order | 1 | | 17 | Stop? | pa_automatische_stop | select | menu_order | 1 | | 18 | Breedte (mm) | pa_breedte | text | menu_order | 1 | | 19 | Connector? | pa_connector | select | menu_order | 1 | | 20 | Diagram | pa_diagram | text | menu_order | 1 | | 21 | Diepte (mm) | pa_diepte | text | menu_order | 1 | | 22 | Lengte (mm) | pa_lengte | text | menu_order | 1 | | 30 | Materiaal | pa_materiaal | select | name | 1 | | 25 | Model | pa_model | select | menu_order | 1 | | 23 | Originele Widget | pa_originele_widget | select | menu_order | 1 | | 28 | Productlijn | pa_productlijn | select | menu_order | 1 | | 24 | Stroomdraad? | pa_stroomdraad | select | menu_order | 1 | | 26 | Submodel | pa_submodel | select | menu_order | 1 | | 27 | Veer? | pa_veer | select | menu_order | 1 | | 31 | Zoeken-op-afbeelding | pa_zoeken-op-afbeelding | select | menu_order | 1 | +----+-----------------------+--------------------------+--------+------------+--------------+
wp wc product_attribute update
Pas de definitie van een taxonomie aan. De truuk is, dat je met de flag aangeeft, welk veld je wilt aanpassen, gevolgd door de nieuwe waarde
wp help wc product_attribute update NAME wp wc product_attribute update DESCRIPTION Update an existing item. SYNOPSIS wp wc product_attribute update <id> [--id=<id>] [--name=<name>] [--slug=<slug>] [--type=<type>] [--order_by=<order_by>] [--has_archives=<has_archives>] [--porcelain] OPTIONS <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--name=<name>] Attribute name. [--slug=<slug>] An alphanumeric identifier for the resource unique to its type. [--type=<type>] Type of attribute. [--order_by=<order_by>] Default sort order. [--has_archives=<has_archives>] Enable/Disable attribute archives. [--porcelain] Output just the id when the operation is successful.
Voorbeeld
In dit voorbeeld wordt de naam aangepast. Merk op dat de slug automatisch meeverandert.
$ wp wc product_attribute get 29 --user=4 +--------------+-------------+ | Field | Value | +--------------+-------------+ | id | 29 | | name | Apparaat | | slug | pa_apparaat | | type | select | | order_by | menu_order | | has_archives | true | +--------------+-------------+ $ wp wc product_attribute update 29 --user=4 --name="Device" Success: Updated product_attribute 29. $ wp wc product_attribute get 29 --user=4 +--------------+------------+ | Field | Value | +--------------+------------+ | id | 29 | | name | Device | | slug | pa_device | | type | select | | order_by | menu_order | | has_archives | false | +--------------+------------+
Meerdere updates tegelijkertijd
Je kunt meerdere aspecten tegelijkertijd bijwerken. Bv:
wp wc product_attribute update 29 --user=4 --name="Device" --has_archives=1
wp wc product_attribute_term
$ wp help wc product_attribute_term NAME wp wc product_attribute_term SYNOPSIS wp wc product_attribute_term <command> SUBCOMMANDS create Create a new item. delete Delete an existing item. get Get a single item. list List all items. update Update an existing item.
wp wc product_attribute_term create
wp wc product_attribute_term delete
NAME wp wc product_attribute_term delete DESCRIPTION Delete an existing item. SYNOPSIS wp wc product_attribute_term delete <attribute_id> <id> [--id=<id>] [--attribute_id=<attribute_id>] [--force=<force>] [--porcelain] OPTIONS <attribute_id> Attribute ID. <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--attribute_id=<attribute_id>] Unique identifier for the attribute of the terms. [--force=<force>] Required to be true, as resource does not support trashing. [--porcelain] Output just the id when the operation is successful.
Voorbeelden
wp --user=4 wc product_attribute_term delete 30 44268 --force=true
wp wc product_attribute_term get
wp wc product_attribute_term list
Voorbeeld (taxonomy 29):
wp wc product_attribute_term list 29 --user=4 +-------+------------------+------------------+---------------------------------+------------+-------+ | id | name | slug | description | menu_order | count | +-------+------------------+------------------+---------------------------------+------------+-------+ | 45244 | Alternator | alternator | Alle widgets voor alternators | 0 | 12 | | 34601 | Blazer | blazer | Alle widgers voor Blazer | 0 | 26 | | 45246 | Boorhamer | boorhamer | Alle widgets voor boorhamers | 0 | 0 | | 34582 | Boormachine | boormachine | Alle widgets - Boormachine | 0 | 2929 | +-------+------------------+------------------+---------------------------------+------------+-------+
wp wc product_attribute_term update
wp wc product_attribute_term update usage: wp wc product_attribute_term update <attribute_id> <id> [--id=<id>] [--attribute_id=<attribute_id>] [--name=<name>] [--slug=<slug>] [--description=<description>] [--menu_order=<menu_order>] [--porcelain]
Voorbeeld
Attribuut-taxonomie nummer 29, is elders getoond. 45244 is het id van de individuele term. Blijkbaar moet je beide id's geven.
$ wp wc product_attribute_term update 29 45244 --description="All carbon brushes for alternators" --user=4 Success: Updated product_attribute_term 45244.
wp wc product_cat
Werken met taxons in de product_cat
-taxonomie: Creëer, verwijder, update en geef taxons en hun eigenschappen weer.
Een WooCommerce-site kent precies één product_cat-taxonomie! Daarom heb je geen commando's om met de product_cat-taxonomie als geheel te werken!
$ wp help wc product_cat NAME wp wc product_cat SYNOPSIS wp wc product_cat <command> SUBCOMMANDS create Create a new item. delete Delete an existing item. get Get a single item. list List all items. update Update an existing item.
Bronnen
wp wc product_cat create
Maak een nieuwe taxon aan in de product_cat
-taxonomie:
$ wp help wc product_cat create NAME wp wc product_cat create DESCRIPTION Create a new item. SYNOPSIS wp wc product_cat create --name=<name> [--slug=<slug>] [--parent=<parent>] [--description=<description>] [--display=<display>] [--image=<image>] [--menu_order=<menu_order>] [--porcelain] OPTIONS --name=<name> Name for the resource. [--slug=<slug>] An alphanumeric identifier for the resource unique to its type. [--parent=<parent>] The ID for the parent of the resource. [--description=<description>] HTML description of the resource. [--display=<display>] Category archive display type. [--image=<image>] Image data. [--menu_order=<menu_order>] Menu order, used to custom sort the resource. [--porcelain] Output just the id when the operation is successful.
wp wc product_cat delete
Verwijder een bestaande taxon uit de product_cat
-taxonomie:
$ wp help wc product_cat delete NAME wp wc product_cat delete DESCRIPTION Delete an existing item. SYNOPSIS wp wc product_cat delete <id> [--id=<id>] [--force=<force>] [--porcelain] OPTIONS <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--force=<force>] Required to be true, as resource does not support trashing. [--porcelain] Output just the id when the operation is successful.
wp wc product_cat get
Lees gegevens uit van individuele product_cat
-taxons:
$ wp help wc product_cat get NAME wp wc product_cat get DESCRIPTION Get a single item. SYNOPSIS wp wc product_cat get <id> [--id=<id>] [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>] OPTIONS <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--context=<context>] Scope under which the request is made; determines fields present in response. [--fields=<fields>] Limit response to specific fields. Defaults to all fields. [--field=<field>] Get the value of an individual field. [--format=<format>] Render response in a particular format. --- default: table options: - table - json - csv - ids - yaml - count - headers - body - envelope ---
Voorbeelden
Gebruik bv. wp wc product_cat --user=4 list --per_page=2
om een taxon-id te achterhalen. Met dit taxon-id:
wp wc product_cat --user=4 get 44274 +-------------+------------------------------+ | Field | Value | +-------------+------------------------------+ | id | 44274 | | name | Alberka | | slug | alberka | | parent | 0 | | description | Alle widgets voor Alberka | | display | default | | image | null | | menu_order | 79 | | count | 8 | +-------------+------------------------------+
Count geeft het aantal producten aan, die met deze taxon zijn geassociëerd.
Verkrijg alleen het description-veld:
$ wp wc product_cat --user=4 get 44276 --field="description" Alle widgets voor Advanilla
--context
De flag --context
is niet beschreven op de site of via help
. Door een willekeurige waarde op te geven, krijg je meer info:
$ wp wc product_cat --user=4 get 44276 --field="description" --context="blub" Error: Invalid parameter(s): context {"status":400,"params":{"context":"context
Ik merk echter geen verschil in output - Vooral niet binnen het kader van het leading character-probleem wat hieronder genoemd wordt:
$ echo "»"$(wp wc product_cat --user=4 get 44277 --field="description" --context="view")"«" » Alle widgets voor A-C« $ echo "»"$(wp wc product_cat --user=4 get 44277 --field="description" --context="edit")"«" » Alle widgets voor A-C«
Probleem met leading character
Dit commando lijkt een leading ao
-karakter (line feed) toe te voegen aan de output.
Eerste voorbeeld:
echo "»"$(wp wc product_cat --user=4 get 44276 --field="description")"«" » All widgets for Advance«
Tweede voorbeeld:
$ i1=$(wp wc product_cat --user=4 get 18869 --field="description") $ echo "»"$i1"«" » Alle widgets voor AFX«
Gebruik van de flag --format
lijkt niet te helpen:
i1=$(wp wc product_cat --user=4 get 18869 --field="description") echo "»"$i1"«" i1=$(wp wc product_cat --user=4 get 18869 --field="description" --format="csv") echo "format=csv: »"$i1"«" i1=$(wp wc product_cat --user=4 get 18869 --field="description" --format="body") echo "format=body: »"$i1"«" i1=$(wp wc product_cat --user=4 get 18869 --field="description" --format="json") echo "format=json: »"$i1"«" i1=$(wp wc product_cat --user=4 get 18869 --field="description" --format="envelope") echo "format=envelope: »"$i1"«"
Oplossing (beter dan niets): Voeg |xargs
toe aan het wp-commando:
$ i1=$(wp wc product_cat --user=4 get 18869 --field="description"|xargs) $ echo "»"$i1"«" »gelukt!«
wp wc product_cat list
Toon alle taxons uit de product_cat
-taxonomie of een deelverzameling daarvan. Merk op dat je met dit commando niet kunt filteren op individuele id's. Daar heb je wp wc product_cat get
voor.
$ wp help wc product_cat list NAME wp wc product_cat list DESCRIPTION List all items. SYNOPSIS wp wc product_cat list [--context=<context>] [--page=<page>] [--per_page=<per_page>] [--search=<search>] [--exclude=<exclude>] [--include=<include>] [--offset=<offset>] [--order=<order>] [--orderby=<orderby>] [--hide_empty=<hide_empty>] [--parent=<parent>] [--product=<product>] [--slug=<slug>] [--fields=<fields>] [--field=<field>] [--format=<format>] OPTIONS [--context=<context>] Scope under which the request is made; determines fields present in response. [--page=<page>] Current page of the collection. [--per_page=<per_page>] Maximum number of items to be returned in result set. [--search=<search>] Limit results to those matching a string. [--exclude=<exclude>] Ensure result set excludes specific IDs. [--include=<include>] Limit result set to specific ids. [--offset=<offset>] Offset the result set by a specific number of items. Applies to hierarchical taxonomies only. [--order=<order>] Order sort attribute ascending or descending. [--orderby=<orderby>] Sort collection by resource attribute. [--hide_empty=<hide_empty>] Whether to hide resources not assigned to any products. [--parent=<parent>] ← Gebruik parent-ID Limit result set to resources assigned to a specific parent. Applies to hierarchical taxonomies only. [--product=<product>] Limit result set to resources assigned to a specific product. [--slug=<slug>] Limit result set to resources with a specific slug. [--fields=<fields>] Limit response to specific fields. Defaults to all fields. [--field=<field>] Get the value of an individual field. [--format=<format>] Render response in a particular format. --- default: table options: - table - json - csv - ids - yaml - count - headers - body - envelope ---
--field
Gebruik de vlag --field
om de output van één veld te krijgen. Voorbeeld:
$ wp wc product_cat --user=4 list --field="description" All widgets for Alberko Alle widgets voor Advanilla ...
--format="count"
Met de optie --format="count"
wordt het aantal taxons vermeld. Dit is inclusief subtaxons
wp wc product_cat --user=4 list --format=count 706
--format="ids"
Met de flag --format="ids"
worden alleen de id's van taxons geretourneerd. Cruciaal als je de output van dit commando wilt gebruiken als input voor verdere bewerkingen. Voorbeelden:
$ wp wc product_cat --user=4 list --format=ids 44274 44276 18869 18906 44277 44278 45130 45146 44279 18926 44280 18870 44281 45165 18891 18936 18907 44283 18867 19038 19042 19043 19045 19133 19292 19293 19294 19309 45167 45139 18938 18954 18967 18982 18983 18985 18986 18988 18993 19012 19031 19046 19071 19094 19096 19112 19118 19140 19164 19171 19214 19234 19240 19241 19245 19263 19267 19281 19305 19307 19319 19340 19356 18866 18897 44282 19316 19369 45144 44286 18872 44297 44299 44285 18921 44812 44301 44305 18922 45134 44309 45147 44311 18868 18913 45170 44313 18903 45140 45141 18911 45242 18931 44315 18882 18925 18889 18894 44318 18899
Er worden max. 100 items getourneerd. Kijk maar:
$ wp wc product_cat --user=4 list --format=ids | wc -w 100
--offset
Je kunt max. 100 taxons per keer zien. Gebruik daarom de flag --offset
om voorbij de eerste 100 taxons te komen
--parent
Met --parent
kun je filteren op parent-taxons.
Voorbeeld: Vind de eerste 10 taxons zonder parent-categorie:
wp wc product_cat --user=4 list --per_page=10 --parent=0
--per_page
Standaard worden er maximaal 100 items getoond. Dit getal kun je verlagen met --per_page
, maar niet verhogen. Kijk maar:
wp wc product_cat --user=4 list --per_page=200 Error: Invalid parameter(s): per_page {"status":400,"params":{"per_page":"per_page must be between 1 (inclusive) and 100 (inclusive)"},"details":{"per_page":{"code":"rest_out_of_bounds","message":"per_page must be between 1 (inclusive) and 100 (inclusive)","data":null}}}
--search
Filter op strings die voorkomen in de velden name
en slug
. Standaard wordt er niet gezocht in het veld description
. Wellicht is dat mogelijk, maar weet ik op dit moment niet hoe dat te doen.
Voorbeeld:
$ wp wc product_cat --user=4 list --search="Hamer"
wp wc product_cat update
Bewerk een bestaande taxon uit de product_cat
-taxonomie. Geef met een flag aan wat de nieuwe waarde van het betreffende attribuut wordt.
$ wp help wc product_cat update NAME wp wc product_cat update DESCRIPTION Update an existing item. SYNOPSIS wp wc product_cat update <id> [--id=<id>] [--name=<name>] [--slug=<slug>] [--parent=<parent>] [--description=<description>] [--display=<display>] [--image=<image>] [--menu_order=<menu_order>] [--porcelain] OPTIONS <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--name=<name>] Category name. [--slug=<slug>] An alphanumeric identifier for the resource unique to its type. [--parent=<parent>] The ID for the parent of the resource. [--description=<description>] HTML description of the resource. [--display=<display>] Category archive display type. [--image=<image>] Image data. [--menu_order=<menu_order>] Menu order, used to custom sort the resource. [--porcelain] Output just the id when the operation is successful.
Simpel voorbeeld
$ wp wc product_cat --user=4 get 44274 +-------------+------------------------------+ | Field | Value | +-------------+------------------------------+ | id | 44274 | | name | Alberka | | slug | Alberka | | parent | 0 | | description | Alle widgets voor Alberka | | display | default | | image | null | | menu_order | 79 | | count | 8 | +-------------+------------------------------+ $ wp wc product_cat --user=4 update 44274 --description="All widgets for Alberka" Success: Updated product_cat 44274. $ wp wc product_cat --user=4 get 44274 +-------------+------------------------------+ | Field | Value | +-------------+------------------------------+ | id | 44274 | | name | Alberka | | slug | Alberka | | parent | 0 | | description | All widgets for Alberka | | display | default | | image | null | | menu_order | 79 | | count | 8 | +-------------+------------------------------+
Voorbeeld: Find-and-replace
wp wc product_review
wp wc product_shipping_class
wp wc product_tag
wp wc product_variation
wp wc shipping_method
wp wc shipping_zone
wp wc shipping_zone_location
wp wc shipping_zone_method
wp wc shop_coupon
wp wc shop_order
Manage WooCommerce orders. Uitvoer wp help wc shop_order
:
NAME wp wc shop_order SYNOPSIS wp wc shop_order <command> SUBCOMMANDS create Create a new item. delete Delete an existing item. get Get a single item. list List all items. update Update an existing item.
wp wc shop_order delete
Verwijder orders.
Uitvoer van wp help wc shop_order delete
:
NAME wp wc shop_order delete DESCRIPTION Delete an existing item. SYNOPSIS wp wc shop_order delete <id> [--id=<id>] [--force=<force>] [--porcelain] OPTIONS <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--force=<force>] Whether to bypass trash and force deletion. [--porcelain] Output just the id when the operation is successful.
Standaard wordt met dit commando een order verplaatst naar de prullenbak. Om orders direct definitief te verwijderen, gebruik de boolean switch --force
. Bv.:
wp wc shop_order delete --user=4 --force=1 63003
Verwijder (ipv. trashing) alle orders:
wp wc shop_order list --user=4 --field=id | xargs -n1 wp wc shop_order delete --user=4 --force=1
- Er lijken slechts ca. 25 orders per keer te worden verwijderd
- Het duurt ca. 5s/order
- Orders worden niet echt verwijderd, maar verplaatst naar de prullenbak.
Bron: Concatenation (Bash)
wp wc shop_order list
Toon alle orders.
wp help wc shop_order list
(minus de globale opties):
NAME wp wc shop_order list DESCRIPTION List all items. SYNOPSIS wp wc shop_order list [--context=<context>] [--page=<page>] [--per_page=<per_page>] [--search=<search>] [--after=<after>] [--before=<before>] [--dates_are_gmt=<dates_are_gmt>] [--exclude=<exclude>] [--include=<include>] [--offset=<offset>] [--order=<order>] [--orderby=<orderby>] [--parent=<parent>] [--parent_exclude=<parent_exclude>] [--status=<status>] [--customer=<customer>] [--product=<product>] [--dp=<dp>] [--fields=<fields>] [--field=<field>] [--format=<format>] OPTIONS [--context=<context>] Scope under which the request is made; determines fields present in response. [--page=<page>] Current page of the collection. [--per_page=<per_page>] Maximum number of items to be returned in result set. [--search=<search>] Limit results to those matching a string. [--after=<after>] Limit response to resources published after a given ISO8601 compliant date. [--before=<before>] Limit response to resources published before a given ISO8601 compliant date. [--dates_are_gmt=<dates_are_gmt>] Whether to use GMT post dates. [--exclude=<exclude>] Ensure result set excludes specific IDs. [--include=<include>] Limit result set to specific ids. [--offset=<offset>] Offset the result set by a specific number of items. [--order=<order>] Order sort attribute ascending or descending. [--orderby=<orderby>] Sort collection by object attribute. [--parent=<parent>] Limit result set to those of particular parent IDs. [--parent_exclude=<parent_exclude>] Limit result set to all items except those of a particular parent ID. [--status=<status>] Limit result set to orders assigned a specific status. [--customer=<customer>] Limit result set to orders assigned a specific customer. [--product=<product>] Limit result set to orders assigned a specific product. [--dp=<dp>] Number of decimal points to use in each resource. [--fields=<fields>] Limit response to specific fields. Defaults to all fields. [--field=<field>] Get the value of an individual field. [--format=<format>] Render response in a particular format. --- default: table options: - table - json - csv - ids - yaml - count - headers - body - envelope ---
User ID
Ik moest een ID oid. van een admin-account meegeven. Voorbeelden:
wp wc shop_order list --user=4 wp wc shop_order list --user=info@example.com
Om alleen de order-id's op te vragen:
wp wc shop_order list --user=4 --field=id
Max. 100 orders
Dit commando geeft maximaal 100 orders weer. Met de paramater --per_page
kun je dit getal verlagen, maar niet verhogen:
wp wc shop_order list --user=4 --field=id --per_page=100000 Error: Invalid parameter(s): per_page {"status":400,"params":{"per_page":"per_page must be between 1 (inclusive) and 100 (inclusive)"},"details":{"per_page":{"code":"rest_out_of_bounds","message":"per_page must be between 1 (inclusive) and 100 (inclusive)","data":null}}}
Oplossing: Dit commando meerdere keren herhalen. Bv. 68 keer in dit geval (30 juli 2021) om 6.771 orders te verwijderen ;). Daar is vast een slimme dynamische loop voor beschikbaar, maar ik houd het op simpelweg herhalen van het commando:
for i in {1..70} do wp wc shop_order list --user=4 --field=id | xargs -n1 wp wc shop_order delete --user=4 --force=1 done
wp wc shop_order_refund
wp wc tax
$ wp help wc tax NAME wp wc tax SYNOPSIS wp wc tax <command> SUBCOMMANDS create Create a new item. delete Delete an existing item. get Get a single item. list List all items. update Update an existing item.
wp wc tax create
$ wp help wc tax create NAME wp wc tax create DESCRIPTION Create a new item. SYNOPSIS wp wc tax create [--country=<country>] [--state=<state>] [--postcode=<postcode>] [--city=<city>] [--rate=<rate>] [--name=<name>] [--priority=<priority>] [--compound=<compound>] [--shipping=<shipping>] [--order=<order>] [--class=<class>] [--porcelain] OPTIONS [--country=<country>] Country ISO 3166 code. [--state=<state>] State code. [--postcode=<postcode>] Postcode / ZIP. [--city=<city>] City name. [--rate=<rate>] Tax rate. [--name=<name>] Tax rate name. [--priority=<priority>] Tax priority. [--compound=<compound>] Whether or not this is a compound rate. [--shipping=<shipping>] Whether or not this tax rate also gets applied to shipping. [--order=<order>] Indicates the order that will appear in queries. [--class=<class>] Tax class. [--porcelain] Output just the id when the operation is successful.
- Country codes: Gebruik de ISO 3166 Alpha-2-code: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
- Benamingen & tarieven EU-landen: BTW & online marketing#BTW-tarieven EU-landen
wp wc tax delete
$ wp help wc tax delete NAME wp wc tax delete DESCRIPTION Delete an existing item. SYNOPSIS wp wc tax delete <id> [--id=<id>] [--force=<force>] [--porcelain] OPTIONS <id> The ID for the resource. [--id=<id>] Unique identifier for the resource. [--force=<force>] Required to be true, as resource does not support trashing. [--porcelain] Output just the id when the operation is successful.
Voorbeeld
Ondanks de foutmelding is het commando met succes uitgevoerd:
$ wp wc tax --user=4 delete 4 --force=true Error: The resource cannot be deleted. {"status":500}
Voorbeeld: Verwijder alle bestaande tarieven
In deze situatie waren er al een hoop tarieven gedefineerd. Die wilde ik graag in één keer verwijderen:
- Merk opnieuw op, dat je de foutmeldingen kunt negeren
- Merk op dat de rijen in de tabel ogenschijnlijk ongesorteerd zijn. Gelukkig boeit dat op geen enkele manier.
$ wp --user=4 wc tax list +----+---------+-------+----------+------+---------+------+----------+----------+----------+-------+-----------+ | id | country | state | postcode | city | rate | name | priority | compound | shipping | order | class | +----+---------+-------+----------+------+---------+------+----------+----------+----------+-------+-----------+ | 44 | IE | | | | 23.0000 | VAT | 1 | | 1 | 0 | standard | | 57 | | | | | 0.0000 | VAT | 1 | | 1 | 0 | zero-rate | | 56 | SK | | | | 20.0000 | VAT | 1 | | 1 | 0 | standard | | 55 | SI | | | | 22.0000 | VAT | 1 | | 1 | 0 | standard | | 54 | SE | | | | 25.0000 | VAT | 1 | | 1 | 0 | standard | | 53 | RO | | | | 19.0000 | VAT | 1 | | 1 | 0 | standard | | 52 | PT | | | | 23.0000 | VAT | 1 | | 1 | 0 | standard | | 51 | PL | | | | 23.0000 | VAT | 1 | | 1 | 0 | standard | | 50 | NL | | | | 21.0000 | VAT | 1 | | 1 | 0 | standard | | 49 | MT | | | | 18.0000 | VAT | 1 | | 1 | 0 | standard | | 48 | LV | | | | 21.0000 | VAT | 1 | | 1 | 0 | standard | | 47 | LU | | | | 17.0000 | VAT | 1 | | 1 | 0 | standard | | 46 | LT | | | | 21.0000 | VAT | 1 | | 1 | 0 | standard | | 45 | IT | | | | 22.0000 | VAT | 1 | | 1 | 0 | standard | | 30 | AT | | | | 20.0000 | VAT | 1 | | 1 | 0 | standard | | 43 | HU | | | | 27.0000 | VAT | 1 | | 1 | 0 | standard | | 42 | HR | | | | 25.0000 | VAT | 1 | | 1 | 0 | standard | | 41 | FR | | | | 20.0000 | VAT | 1 | | 1 | 0 | standard | | 40 | FI | | | | 24.0000 | VAT | 1 | | 1 | 0 | standard | | 39 | ES | | | | 21.0000 | VAT | 1 | | 1 | 0 | standard | | 38 | EL | | | | 24.0000 | VAT | 1 | | 1 | 0 | standard | | 37 | EE | | | | 20.0000 | VAT | 1 | | 1 | 0 | standard | | 36 | DK | | | | 25.0000 | VAT | 1 | | 1 | 0 | standard | | 35 | DE | | | | 19.0000 | VAT | 1 | | 1 | 0 | standard | | 34 | CZ | | | | 21.0000 | VAT | 1 | | 1 | 0 | standard | | 33 | CY | | | | 19.0000 | VAT | 1 | | 1 | 0 | standard | | 32 | BG | | | | 20.0000 | VAT | 1 | | 1 | 0 | standard | | 31 | BE | | | | 21.0000 | VAT | 1 | | 1 | 0 | standard | +----+---------+-------+----------+------+---------+------+----------+----------+----------+-------+-----------+ $ wp --user=4 wc tax list --field=id | xargs -n1 wp --user=4 wc tax delete --force=true Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} Error: The resource cannot be deleted. {"status":500} $ wp --user=4 wc tax list +----+---------+-------+----------+------+------+------+----------+----------+----------+-------+-------+ | id | country | state | postcode | city | rate | name | priority | compound | shipping | order | class | +----+---------+-------+----------+------+------+------+----------+----------+----------+-------+-------+ +----+---------+-------+----------+------+------+------+----------+----------+----------+-------+-------+
wp wc tax get
wp wc tax list
$ wp help wc tax list NAME wp wc tax list DESCRIPTION List all items. SYNOPSIS wp wc tax list [--context=<context>] [--page=<page>] [--per_page=<per_page>] [--offset=<offset>] [--order=<order>] [--orderby=<orderby>] [--class=<class>] [--fields=<fields>] [--field=<field>] [--format=<format>]
Voorbeeld:
$ wp wc --user=4 tax list +----+---------+-------+----------+------+---------+------+----------+----------+----------+-------+----------+ | id | country | state | postcode | city | rate | name | priority | compound | shipping | order | class | +----+---------+-------+----------+------+---------+------+----------+----------+----------+-------+----------+ | 1 | NL | | | | 21.0000 | BTW | 1 | | 1 | 0 | standard | | 2 | DE | | | | 19.0000 | MwSt | 1 | | 1 | 1 | standard | | 3 | | | | | 21.0000 | BTW | 1 | | 1 | 2 | standard | +----+---------+-------+----------+------+---------+------+----------+----------+----------+-------+----------+
wp wc tax update
wp wc tax_class
$ wp help wx tax_class NAME wp wc tax_class SYNOPSIS wp wc tax_class <command> SUBCOMMANDS create Create a new item. delete Delete an existing item. get Get a single item. list List all items.
wp wc tax_class create
wp wc tax_class delete
$ wp help wc tax_class delete NAME wp wc tax_class delete DESCRIPTION Delete an existing item. SYNOPSIS wp wc tax_class delete <slug> [--force=<force>] [--porcelain] OPTIONS <slug> The slug for the resource. [--force=<force>] Required to be true, as resource does not support trashing. [--porcelain] Output just the id when the operation is successful.
Voorbeeld:
$ wp --user=4 wc tax_class list +--------------------+--------------------+ | slug | name | +--------------------+--------------------+ | standard | Standard rate | | gereduceerd-tarief | Gereduceerd tarief | | nultarief | Nultarief | | reduced-rate | Reduced rate | | zero-rate | Zero rate | +--------------------+--------------------+ # Delete redundant tax classes ######################################## # # * Stick to EN names # * Keep the reduced-rate, just to be reminded that it exists # * "--force=true" is needed, as there is no trashbin for # tax classes # wp --user=4 wc tax_class delete gereduceerd-tarief --force=true wp --user=4 wc tax_class delete nultarief --force=true
wp wc tax_class get
wp wc tax_class list
Voorbeeld:
$ wp --user=4 wc tax_class list +--------------------+--------------------+ | slug | name | +--------------------+--------------------+ | standard | Standard rate | | gereduceerd-tarief | Gereduceerd tarief | | nultarief | Nultarief | | reduced-rate | Reduced rate | | zero-rate | Zero rate | +--------------------+--------------------+
wp wc tool
wp wc tool usage: wp wc tool list [--fields=<fields>] [--field=<field>] [--format=<format>] or: wp wc tool run <id> See 'wp help wc tool <command>' for more information on a specific command.
Uitvoer wp wc tool --user=4
:
+------------------------------------+----------------------------------+-----------------------------+-----------------------------------------------------------------------+ | id | name | action | description | +------------------------------------+----------------------------------+-----------------------------+-----------------------------------------------------------------------+ | clear_transients | WooCommerce transients | Clear transients | Clear the product/shop transients cache. | | clear_expired_transients | Expired transients | Clear transients | Clear ALL expired transients from WordPress. | | delete_orphaned_variations | Orphaned variations | Delete orphaned variations | Delete all variations which have no parent. | | clear_expired_download_permissions | Used-up download permissions | Clean up download | Delete expired download permissions and permissions | | | | permissions | with 0 remaining downloads. | | regenerate_product_lookup_tables | Product lookup tables | Regenerate | Regenerate product lookup table data. This process may | | | | | take a while | | recount_terms | Term counts | Recount terms | Recount product terms - useful when changing your | | settings in a way which hides products from the catalog. | | reset_roles | Capabilities | Reset capabilities | Reset the admin, customer and shop_manager roles to | | default. Use this if your users cannot access all of the WooCommerce | | | | | admin pages. | | clear_sessions | Clear customer sessions | Clear | Delete all customer session data from the | | database, including current carts and saved carts in the database | | clear_template_cache | Clear template cache | Clear | Empty the template cache. | | install_pages | Create default WooCommerce pages | Create pages | Install all the missing WooCommerce pages. | | Pages already defined and set up will not be replaced | | delete_taxes | Delete WooCommerce tax rates | Delete tax rates | Delete ALL of your tax rate; use with caution | | This action cannot be reversed | | regenerate_thumbnails | Regenerate shop thumbnails | Regenerate | Regenerate all shop thumbnails to match your theme and/or | image settings | | db_update_routine | Update database | Update database | Update your WooCommerce database to the latest | | version. Please ensure you make sufficient backups before proceeding | | verify_db_tables | Verify base database tables | Verify database | Verify if all base database tables are present. | | clear_woocommerce_analytics_cache | Clear analytics cache | Clear | Reset the cached values used in WooCommerce Analytics. If numbers | | | | | still look off, try Reimporting Historical Data | +------------------------------------+----------------------------------+-----------------------------+-----------------------------------------------------------------------+