Documentation · Cartnorm B2B

Developers

All hooks below are in Cartnorm B2B 0.3.2. Namespace of the PHP classes: Cartnorm\B2B.

Order meta (VAT evidence)

Read with $order->get_meta( '…' ). Invoice and ERP plugins can print or export these.

Meta keyContent
_cartnorm_b2b_vat_idVAT ID with country prefix, e.g. DE123456789
_cartnorm_b2b_vat_countryCountry of the VAT ID
_cartnorm_b2b_vat_destinationCountry that decided about VAT (billing or shipping)
_cartnorm_b2b_vies_statusvalid, invalid, unavailable or format_invalid
_cartnorm_b2b_vies_consultationVIES consultation number
_cartnorm_b2b_vies_checked_atTime of the VIES check (UTC, ISO 8601)
_cartnorm_b2b_vies_name, _cartnorm_b2b_vies_addressTrader data returned by VIES (empty for some countries)
_cartnorm_b2b_vat_treatmentstandard, intra_community_supply, reverse_charge, mixed or pending_verification
_cartnorm_b2b_vat_reasoncross_border, same_country, outside_eu, country_mismatch, invalid, unavailable, verified_after_order …
_cartnorm_b2b_vat_notesArray of legal notes to print on the invoice
_cartnorm_b2b_customer_groupCustomer group at the time of the order
_cartnorm_b2b_localeLanguage of the legal notes
_cartnorm_b2b_quote_idQuote the order was created from

Order item meta _cartnorm_b2b_group_price marks lines that were priced for a group in the admin order editor.

Filters

Groups and prices

FilterArgumentsUse
cartnorm_b2b_user_groupstring $slug, int $user_idGroup of a user; must return an existing slug or retail
cartnorm_b2b_can_assign_groupbool $allowed, int $user_idWhether the current user may change a customer’s group
cartnorm_b2b_group_price$price, WC_Product $product, string $group, string $sourceGroup price before quantity prices; return null for the normal price
cartnorm_b2b_never_above_retailbool $never, WC_Product $productDefault true: a group price is never higher than the current price
cartnorm_b2b_tier_quantityfloat $quantity, array $item, string $cart_keyQuantity used to pick a quantity price (default: total of the same product or variation in the cart)
cartnorm_b2b_convert_price$converted, $amountConvert fixed group and quantity prices for currency switchers other than WCML
cartnorm_b2b_show_excl_suffixbool $showShow the “excl. VAT” suffix (default: on unless Germanized is active)
cartnorm_b2b_unitsarray $unitsUnits of the simple unit price (key => label)

VAT and VIES

FilterArgumentsUse
cartnorm_b2b_vat_field_modestring $mode, string $grouprequired, optional or hidden for the current visitor
cartnorm_b2b_vat_decisionarray $decision, string $raw, string $countryThe full VAT decision for a VAT ID and destination country
cartnorm_b2b_require_matching_countrybool $requireDefault true: the VAT ID country must match the address country
cartnorm_b2b_is_servicebool $service, WC_Order_Item_Product $itemGoods or service (default: virtual products are services)
cartnorm_b2b_legal_phrasesarray $tableBuilt-in phrase table (keys: language codes such as de or locales)
cartnorm_b2b_legal_note_goodsstring $note, string $localeNote for goods (Art. 138)
cartnorm_b2b_legal_note_servicesstring $note, string $localeNote for services (Art. 196)
cartnorm_b2b_legal_notesarray $notes, string $treatment, WC_Order $order, array $decisionAll notes stored on an order
cartnorm_b2b_order_languagestring $locale, WC_Order $orderLanguage of the notes
cartnorm_b2b_vies_timeoutint $secondsVIES request timeout (default 10)
cartnorm_b2b_vies_cache_ttlint $ttl, array $resultCache time of a VIES result in seconds

Order rules

FilterArgumentsUse
cartnorm_b2b_group_order_rulesarray $rules, string $slugMinimum order value and number of items of a group
cartnorm_b2b_product_quantity_rulearray|null $rule, WC_Product $product, string $slugMinimum, maximum and pack size of a product for a group
cartnorm_b2b_min_order_cart_amountfloat $amount, WC_Cart $cart, bool $inclAmount compared with the minimum order value
cartnorm_b2b_cart_rule_messagesarray $messages, WC_Cart $cart, string $slugMessages shown in the cart
cartnorm_b2b_classic_notice_typestring $typeerror (default) or notice in the classic cart
cartnorm_b2b_is_store_api_checkoutbool $checkout, string $routeWhether a Store API request is a checkout (blocked by the rules)

Quotes, registration, store mode, caching

FilterArgumentsUse
cartnorm_b2b_quote_modestring $mode, string $audienceoff, both or only for guest, retail or a group slug
cartnorm_b2b_hide_pricesbool $hidden, string $audienceHide prices for the current visitor
cartnorm_b2b_add_to_quote_labelstring $labelButton text
cartnorm_b2b_registration_errorsWP_Error $errors, array $fields, int $user_idYour own validation of applications
cartnorm_b2b_auto_approvebool $auto, int $user_id, array $applicationDecide about automatic approval
cartnorm_b2b_rate_limitint $max, string $actionRequests per IP address (default 5)
cartnorm_b2b_store_lockedbool $locked, int $user_idWhether the visitor is kept out of a “B2B only” shop
cartnorm_b2b_store_noticestring $htmlNotice for visitors of a “B2B only” shop
cartnorm_b2b_is_catalog_requestbool $catalogWhether the request is a catalog page (catalog restriction)
cartnorm_b2b_private_pagebool $privateWhether the current page must not be cached
cartnorm_b2b_cache_pluginsarray $pluginsDetected cache plugins (id => [ name, detected ])

Other

FilterArgumentsUse
cartnorm_b2b_settingsarray $settingsEffective settings
cartnorm_b2b_keep_data_on_uninstallbool $keepKeep all data when the plugin is deleted

Actions

ActionArgumentsWhen
cartnorm_b2b_loaded—The plugin has loaded
cartnorm_b2b_vies_checkedarray $result, string $prefix, string $numberAfter a live VIES request (not for cached results)
cartnorm_b2b_vat_recordedWC_Order $order, array $decisionVAT evidence was stored on an order
cartnorm_b2b_vat_recheckedWC_Order $order, array $resultA pending VAT ID was checked again
cartnorm_b2b_quote_createdint $quote_idA quote request was sent
cartnorm_b2b_quote_after_answerint $quote_id, bool $sentYou saved (and maybe sent) an answer
cartnorm_b2b_quote_status_changedint $quote_id, string $statusA quote changed status
cartnorm_b2b_quote_convertedint $quote_id, WC_Order $orderAn order was created from a quote
cartnorm_b2b_application_submittedint $user_id, array $application, bool $createdA wholesale application was sent
cartnorm_b2b_application_approvedint $user_id, string $groupAn application was approved
cartnorm_b2b_application_rejectedint $user_idAn application was rejected

Quotes as posts

Quotes are posts of the private post type cartnorm_b2b_quote with the post statuses cnb2b-new, cnb2b-answered, cnb2b-accepted, cnb2b-expired and cnb2b-converted.

Shortcodes

  • [cartnorm_b2b_quote]: quote request and accept page
  • [cartnorm_b2b_registration]: wholesale registration form

PHP

// Put a user into a group; 'retail' removes them from their group.
// Returns false if the group does not exist.
\Cartnorm\B2B\Groups::assign( $user_id, 'wholesale' );

// Name and value of the cache cookie.
\Cartnorm\B2B\Cache::COOKIE;                      // 'cartnorm_b2b_group'
\Cartnorm\B2B\Cache::cookie_value( 'wholesale' );

Example: treat a product category as services

add_filter( 'cartnorm_b2b_is_service', function ( $service, $item ) {
	$product = $item->get_product();
	if ( $product && has_term( 'installation', 'product_cat', $product->get_parent_id() ?: $product->get_id() ) ) {
		return true;
	}
	return $service;
}, 10, 2 );

Something unclear or missing? Write to [email protected].