WooCommerce Code Reference

Search results

WooCommerceFunctions

Table of Contents

wc_lostpassword_url() Returns the url to the lost password endpoint url.
wc_customer_edit_account_url() Get the link to the edit account details page.
wc_edit_address_i18n() Get the edit address slug translation.
wc_get_account_menu_items() Get My Account menu items.
wc_get_account_menu_item_classes() Get account menu item classes.
wc_get_account_endpoint_url() Get account endpoint URL.
wc_get_account_orders_columns() Get My Account > Orders columns.
wc_get_account_downloads_columns() Get My Account > Downloads columns.
wc_get_account_payment_methods_columns() Get My Account > Payment methods columns.
wc_get_account_payment_methods_types() Get My Account > Payment methods types
wc_get_account_orders_actions() Get account orders actions.
wc_get_account_formatted_address() Get account formatted address.
wc_get_account_saved_payment_methods_list() Returns an array of a user's saved payments list for output on the account tab.
wc_get_account_saved_payment_methods_list_item_cc() Controls the output for credit cards on the my account page.
wc_get_account_saved_payment_methods_list_item_echeck() Controls the output for eChecks on the my account page.
wc_get_text_attributes() Gets text attributes from a string.
wc_get_text_attributes_filter_callback() See if an attribute is actually valid.
wc_implode_text_attributes() Implode an array of attributes using WC_DELIMITER.
wc_get_attribute_taxonomies() Get attribute taxonomies.
wc_get_attribute_taxonomy_ids() Get (cached) attribute taxonomy ID and name pairs.
wc_get_attribute_taxonomy_labels() Get (cached) attribute taxonomy label and name pairs.
wc_attribute_taxonomy_name() Get a product attribute name.
wc_variation_attribute_name() Get the attribute name used when storing values in post meta.
wc_attribute_taxonomy_name_by_id() Get a product attribute name by ID.
wc_attribute_taxonomy_id_by_name() Get a product attribute ID by name.
wc_attribute_label() Get a product attributes label.
wc_attribute_orderby() Get a product attributes orderby setting.
wc_get_attribute_taxonomy_names() Get an array of product attribute taxonomies.
wc_get_attribute_types() Get attribute types.
wc_has_custom_attribute_types() Check if there are custom attribute types.
wc_get_attribute_type_label() Get attribute type label.
wc_check_if_attribute_name_is_reserved() Check if attribute name is reserved.
wc_attributes_array_filter_visible() Callback for array filter to get visible only.
wc_attributes_array_filter_variation() Callback for array filter to get variation attributes only.
wc_is_attribute_in_product_name() Check if an attribute is included in the attributes area of a variation name.
wc_array_filter_default_attributes() Callback for array filter to get default attributes. Will allow for '0' string values, but regard all other class PHP FALSE equivalents normally.
wc_get_attribute() Get attribute data by ID.
wc_create_attribute() Create attribute.
wc_update_attribute() Update an attribute.
wc_delete_attribute() Delete attribute by ID.
wc_attribute_taxonomy_slug() Get an unprefixed product attribute name.
wc_protected_product_add_to_cart() Prevent password protected products being added to the cart.
wc_empty_cart() Clears the cart session when called.
wc_load_persistent_cart() Load the persistent cart.
wc_get_raw_referer() Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.
wc_add_to_cart_message() Add to cart messages.
wc_format_list_of_items() Comma separate a list of item names, and replace final comma with 'and'.
wc_clear_cart_after_payment() Clear cart after payment.
wc_cart_totals_subtotal_html() Get the subtotal.
wc_cart_totals_shipping_html() Get shipping methods.
wc_cart_totals_taxes_total_html() Get taxes total.
wc_cart_totals_coupon_label() Get a coupon label.
wc_cart_totals_coupon_html() Get coupon display HTML.
wc_cart_totals_order_total_html() Get order total html including inc tax if needed.
wc_cart_totals_fee_html() Get the fee value.
wc_cart_totals_shipping_method_label() Get a shipping methods full label including price.
wc_cart_round_discount() Round discount.
wc_get_chosen_shipping_method_ids() Gets chosen shipping method IDs from chosen_shipping_methods session, without instance IDs.
wc_get_chosen_shipping_method_for_package() Get chosen method for package from session.
wc_get_default_shipping_method_for_package() Choose the default method for a package.
wc_shipping_methods_have_changed() See if the methods have changed since the last request.
wc_get_cart_item_data_hash() Gets a hash of important product data that when changed should cause cart items to be invalidated.
is_woocommerce() Is_woocommerce - Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included).
is_shop() Is_shop - Returns true when viewing the product type archive (shop).
is_product_taxonomy() Is_product_taxonomy - Returns true when viewing a product taxonomy archive.
is_product_category() Is_product_category - Returns true when viewing a product category.
is_product_tag() Is_product_tag - Returns true when viewing a product tag.
is_product() Is_product - Returns true when viewing a single product.
is_cart() Is_cart - Returns true when viewing the cart page.
is_checkout() Is_checkout - Returns true when viewing the checkout page.
is_checkout_pay_page() Is_checkout_pay - Returns true when viewing the checkout's pay page.
is_wc_endpoint_url() Is_wc_endpoint_url - Check if an endpoint is showing.
is_account_page() Is_account_page - Returns true when viewing an account page.
is_view_order_page() Is_view_order_page - Returns true when on the view order page.
is_edit_account_page() Check for edit account page.
is_order_received_page() Is_order_received_page - Returns true when viewing the order received page.
is_add_payment_method_page() Is_add_payment_method_page - Returns true when viewing the add payment method page.
is_lost_password_page() Is_lost_password_page - Returns true when viewing the lost password page.
is_ajax() Is_ajax - Returns true when the page is loaded via ajax.
is_store_notice_showing() Is_store_notice_showing - Returns true when store notice is active.
is_filtered() Is_filtered - Returns true when filtering products using layered nav or price sliders.
taxonomy_is_product_attribute() Returns true when the passed taxonomy name is a product attribute.
meta_is_product_attribute() Returns true when the passed meta name is a product attribute.
wc_tax_enabled() Are store-wide taxes enabled?
wc_shipping_enabled() Is shipping enabled?
wc_prices_include_tax() Are prices inclusive of tax?
wc_is_valid_url() Simple check for validating a URL, it must start with http:// or https://.
wc_site_is_https() Check if the home URL is https. If it is, we don't need to do things such as 'force ssl'.
wc_checkout_is_https() Check if the checkout is configured for https. Look at options, WP HTTPS plugin, or the permalink itself.
wc_post_content_has_shortcode() Checks whether the content passed contains a specific short code.
wc_reviews_enabled() Check if reviews are enabled.
wc_review_ratings_enabled() Check if reviews ratings are enabled.
wc_review_ratings_required() Check if review ratings are required.
wc_is_file_valid_csv() Check if a CSV file is valid.
wc_get_coupon_types() Get coupon types.
wc_get_coupon_type() Get a coupon type's name.
wc_get_product_coupon_types() Coupon types that apply to individual products. Controls which validation rules will apply.
wc_get_cart_coupon_types() Coupon types that apply to the cart as a whole. Controls which validation rules will apply.
wc_coupons_enabled() Check if coupons are enabled.
wc_get_coupon_code_by_id() Get coupon code by ID.
wc_get_coupon_id_by_code() Get coupon code by ID.
wc_string_to_bool() Converts a string (e.g. 'yes' or 'no') to a bool.
wc_bool_to_string() Converts a bool to a 'yes' or 'no'.
wc_string_to_array() Explode a string into an array by $delimiter and remove empty values.
wc_sanitize_taxonomy_name() Sanitize taxonomy names. Slug format (no spaces, lowercase).
wc_sanitize_permalink() Sanitize permalink values before insertion into DB.
wc_get_filename_from_url() Gets the filename part of a download URL.
wc_get_dimension() Normalise dimensions, unify to cm then convert to wanted unit value.
wc_get_weight() Normalise weights, unify to kg then convert to wanted unit value.
wc_trim_zeros() Trim trailing zeros off prices.
wc_round_tax_total() Round a tax amount.
wc_legacy_round_half_down() Round half down in PHP 5.2.
wc_format_refund_total() Make a refund total negative.
wc_format_decimal() Format decimal numbers ready for DB storage.
wc_float_to_string() Convert a float to a string without locale formatting which PHP adds when changing floats to strings.
wc_format_localized_price() Format a price with WC Currency Locale settings.
wc_format_localized_decimal() Format a decimal with PHP Locale settings.
wc_format_coupon_code() Format a coupon code.
wc_sanitize_coupon_code() Sanitize a coupon code.
wc_clean() Clean variables using sanitize_text_field. Arrays are cleaned recursively.
wc_check_invalid_utf8() Function wp_check_invalid_utf8 with recursive array support.
wc_sanitize_textarea() Run wc_clean over posted textarea but maintain line breaks.
wc_sanitize_tooltip() Sanitize a string destined to be a tooltip.
wc_array_overlay() Merge two arrays.
wc_stock_amount() Formats a stock amount by running it through a filter.
get_woocommerce_price_format() Get the price format depending on the currency position.
wc_get_price_thousand_separator() Return the thousand separator for prices.
wc_get_price_decimal_separator() Return the decimal separator for prices.
wc_get_price_decimals() Return the number of decimals after the decimal point.
wc_price() Format the price with a currency symbol.
wc_let_to_num() Notation to numbers.
wc_date_format() WooCommerce Date Format - Allows to change date format for everything WooCommerce.
wc_time_format() WooCommerce Time Format - Allows to change time format for everything WooCommerce.
wc_string_to_timestamp() Convert mysql datetime to PHP timestamp, forcing UTC. Wrapper for strtotime.
wc_string_to_datetime() Convert a date string to a WC_DateTime.
wc_timezone_string() WooCommerce Timezone - helper to retrieve the timezone string for a site until.
wc_timezone_offset() Get timezone offset in seconds.
wc_flatten_meta_callback() Callback which can flatten post meta (gets the first value if it's an array).
wc_rgb_from_hex() Convert RGB to HEX.
wc_hex_darker() Make HEX color darker.
wc_hex_lighter() Make HEX color lighter.
wc_hex_is_light() Determine whether a hex color is light.
wc_light_or_dark() Detect if we should use a light or dark color on a background color.
wc_format_hex() Format string as hex.
wc_format_postcode() Format the postcode according to the country and length of the postcode.
wc_normalize_postcode() Normalize postcodes.
wc_format_phone_number() Format phone numbers.
wc_sanitize_phone_number() Sanitize phone number.
wc_strtoupper() Wrapper for mb_strtoupper which see's if supported first.
wc_strtolower() Make a string lowercase.
wc_trim_string() Trim a string and append a suffix.
wc_format_content() Format content to display shortcodes.
wc_format_product_short_description() Format product short description.
wc_format_option_price_separators() Formats curency symbols when saved in settings.
wc_format_option_price_num_decimals() Formats decimals when saved in settings.
wc_format_option_hold_stock_minutes() Formats hold stock option and sets cron event up.
wc_sanitize_term_text_based() Sanitize terms from an attribute text based.
wc_make_numeric_postcode() Make numeric postcode.
wc_format_stock_for_display() Format the stock amount ready for display based on settings.
wc_format_stock_quantity_for_display() Format the stock quantity ready for display.
wc_format_sale_price() Format a sale price for display.
wc_format_price_range() Format a price range for display.
wc_format_weight() Format a weight for display.
wc_format_dimensions() Format dimensions for display.
wc_format_datetime() Format a date for output.
wc_do_oembeds() Process oEmbeds.
wc_get_string_before_colon() Get part of a string before :.
wc_array_merge_recursive_numeric() Array merge and sum function.
wc_implode_html_attributes() Implode and escape HTML attributes for output.
wc_esc_json() Escape JSON for use on HTML or attribute text nodes.
wc_parse_relative_date_option() Parse a relative date option from the settings API into a standard format.
wc_sanitize_endpoint_slug() Format the endpoint slug, strip out anything not allowed in a url.
wc_notice_count() Get the count of notices added, either for all notices (default) or for one.
wc_has_notice() Check if a notice has already been added.
wc_add_notice() Add and store a notice.
wc_set_notices() Set all notices at once.
wc_clear_notices() Unset all notices.
wc_print_notices() Prints messages and errors which are stored in the session, then clears them.
wc_print_notice() Print a single notice immediately.
wc_get_notices() Returns all queued notices, optionally filtered by a notice type.
wc_add_wp_error_notices() Add notices for WP Errors.
wc_kses_notice() Filters out the same tags as wp_kses_post, but allows tabindex for <a> element.
wc_get_notice_data_attr() Get notice data attribute.
wc_get_orders() Standard way of retrieving orders based on certain parameters.
wc_get_order() Main function for returning orders, uses the WC_Order_Factory class.
wc_get_order_statuses() Get all order statuses.
wc_is_order_status() See if a string is an order status.
wc_get_is_paid_statuses() Get list of statuses which are consider 'paid'.
wc_get_is_pending_statuses() Get list of statuses which are consider 'pending payment'.
wc_get_order_status_name() Get the nice name for an order status.
wc_generate_order_key() Generate an order key with prefix.
wc_get_order_id_by_order_key() Finds an Order ID based on an order key.
wc_get_order_types() Get all registered order types.
wc_get_order_type() Get an order type by post type name.
wc_register_order_type() Register order type. Do not use before init.
wc_processing_order_count() Return the count of processing orders.
wc_orders_count() Return the orders count of a specific order status.
wc_downloadable_file_permission() Grant downloadable product access to the file identified by $download_id.
wc_downloadable_product_permissions() Order Status completed - give downloadable product access to customer.
wc_delete_shop_order_transients() Clear all transients cache for order data.
wc_ship_to_billing_address_only() See if we only ship to billing addresses.
wc_create_refund() Create a new order refund programmatically.
wc_refund_payment() Try to refund the payment for an order via the gateway.
wc_restock_refunded_items() Restock items during refund.
wc_get_tax_class_by_tax_id() Get tax class by tax id.
wc_get_payment_gateway_by_order() Get payment gateway class by order data.
wc_order_fully_refunded() When refunding an order, create a refund line item if the partial refunds do not match order total.
wc_order_search() Search orders.
wc_update_total_sales_counts() Update total sales amount for each product within a paid order.
wc_update_coupon_usage_counts() Update used coupon amount for each coupon within an order.
wc_cancel_unpaid_orders() Cancel all unpaid orders after held duration to prevent stock lock for those products.
wc_sanitize_order_id() Sanitize order id removing unwanted characters.
wc_get_order_note() Get an order note.
wc_get_order_notes() Get order notes.
wc_create_order_note() Create an order note.
wc_delete_order_note() Delete an order note.
wc_add_order_item() Add a item to an order (for example a line item).
wc_update_order_item() Update an item for an order.
wc_delete_order_item() Delete an item from the order it belongs to based on item id.
wc_update_order_item_meta() WooCommerce Order Item Meta API - Update term meta.
wc_add_order_item_meta() WooCommerce Order Item Meta API - Add term meta.
wc_delete_order_item_meta() WooCommerce Order Item Meta API - Delete term meta.
wc_get_order_item_meta() WooCommerce Order Item Meta API - Get term meta.
wc_get_order_id_by_order_item_id() Get order ID by order item ID.
wc_get_products() Standard way of retrieving products based on certain parameters.
wc_get_product() Main function for returning products, uses the WC_Product_Factory class.
wc_get_product_object() Get a product object.
wc_product_sku_enabled() Returns whether or not SKUS are enabled.
wc_product_weight_enabled() Returns whether or not product weights are enabled.
wc_product_dimensions_enabled() Returns whether or not product dimensions (HxWxD) are enabled.
wc_delete_product_transients() Clear transient cache for product data.
wc_get_product_ids_on_sale() Function that returns an array containing the IDs of the products that are on sale.
wc_get_featured_product_ids() Function that returns an array containing the IDs of the featured products.
wc_product_post_type_link() Filter to allow product_cat in the permalinks for products.
wc_placeholder_img_src() Get the placeholder image URL either from media, or use the fallback image.
wc_placeholder_img() Get the placeholder image.
wc_get_formatted_variation() Variation Formatting.
wc_scheduled_sales() Function which handles the start and end of scheduled sales via cron.
wc_get_attachment_image_attributes() Get attachment image attributes.
wc_prepare_attachment_for_js() Prepare attachment for JavaScript.
wc_track_product_view() Track product views.
wc_get_product_types() Get product types.
wc_product_has_unique_sku() Check if product sku is unique.
wc_product_force_unique_sku() Force a unique SKU.
wc_product_generate_unique_sku() Recursively appends a suffix until a unique SKU is found.
wc_get_product_id_by_sku() Get product ID by SKU.
wc_get_product_variation_attributes() Get attibutes/data for an individual variation from the database and maintain it's integrity.
wc_get_product_cat_ids() Get all product cats for a product by ID, including hierarchy
wc_get_product_attachment_props() Gets data about an attachment, such as alt text and captions.
wc_get_product_visibility_options() Get product visibility options.
wc_get_product_tax_class_options() Get product tax class options.
wc_get_product_stock_status_options() Get stock status options.
wc_get_product_backorder_options() Get backorder options.
wc_get_related_products() Get related products based on product category and tags.
wc_get_product_term_ids() Retrieves product term ids for a taxonomy.
wc_get_price_including_tax() For a given product, and optionally price/qty, work out the price with tax included, based on store settings.
wc_get_price_excluding_tax() For a given product, and optionally price/qty, work out the price with tax excluded, based on store settings.
wc_get_price_to_display() Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
wc_get_product_category_list() Returns the product categories in a list.
wc_get_product_tag_list() Returns the product tags in a list.
wc_products_array_filter_visible() Callback for array filter to get visible only.
wc_products_array_filter_visible_grouped() Callback for array filter to get visible grouped products only.
wc_products_array_filter_editable() Callback for array filter to get products the user can edit only.
wc_products_array_filter_readable() Callback for array filter to get products the user can view only.
wc_products_array_orderby() Sort an array of products by a value.
wc_products_array_orderby_title() Sort by title.
wc_products_array_orderby_id() Sort by id.
wc_products_array_orderby_date() Sort by date.
wc_products_array_orderby_modified() Sort by modified.
wc_products_array_orderby_menu_order() Sort by menu order.
wc_products_array_orderby_price() Sort by price low to high.
wc_deferred_product_sync() Queue a product for syncing at the end of the request.
wc_update_product_lookup_tables_is_running() See if the lookup table is being generated already.
wc_update_product_lookup_tables() Populate lookup table data for products.
wc_update_product_lookup_tables_column() Populate lookup table column data.
wc_update_product_lookup_tables_rating_count() Populate rating count lookup table data for products.
wc_update_product_lookup_tables_rating_count_batch() Populate a batch of rating count lookup table data for products.
wc_rest_prepare_date_response() Parses and formats a date for ISO8601/RFC3339.
wc_rest_allowed_image_mime_types() Returns image mime types users are allowed to upload via the API.
wc_rest_upload_image_from_url() Upload image from URL.
wc_rest_set_uploaded_image_as_attachment() Set uploaded image as attachment.
wc_rest_validate_reports_request_arg() Validate reports request arguments.
wc_rest_urlencode_rfc3986() Encodes a value according to RFC 3986.
wc_rest_check_post_permissions() Check permissions of posts on REST API.
wc_rest_check_user_permissions() Check permissions of users on REST API.
wc_rest_check_product_term_permissions() Check permissions of product terms on REST API.
wc_rest_check_manager_permissions() Check manager permissions on REST API.
wc_rest_check_product_reviews_permissions() Check product reviews permissions on REST API.
wc_update_product_stock() Update a product's stock amount.
wc_update_product_stock_status() Update a product's stock status.
wc_maybe_reduce_stock_levels() When a payment is complete, we can reduce stock levels for items within an order.
wc_maybe_increase_stock_levels() When a payment is cancelled, restore stock.
wc_reduce_stock_levels() Reduce stock levels for items within an order, if stock has not already been reduced for the items.
wc_trigger_stock_change_notifications() After stock change events, triggers emails and adds order notes.
wc_increase_stock_levels() Increase stock levels for items within an order.
wc_get_held_stock_quantity() See how much stock is being held in pending orders.
wc_reserve_stock_for_order() Hold stock for an order.
wc_release_stock_for_order() Release held stock for an order.
wc_get_low_stock_amount() Return low stock amount to determine if notification needs to be sent
wc_change_get_terms_defaults() Change get terms defaults for attributes to order by the sorting setting, or default to menu_order for sortable taxonomies.
wc_change_pre_get_terms() Adds support to get_terms for menu_order argument.
wc_terms_clauses() Adjust term query to handle custom sorting parameters.
wc_get_object_terms() Helper to get cached object terms and filter by field using wp_list_pluck().
_wc_get_cached_product_terms() Cached version of wp_get_post_terms().
wc_get_product_terms() Wrapper used to get terms for a product.
_wc_get_product_terms_name_num_usort_callback() Sort by name (numeric).
_wc_get_product_terms_parent_usort_callback() Sort by parent.
wc_product_dropdown_categories() WooCommerce Dropdown categories.
wc_walk_category_dropdown_tree() Custom walker for Product Categories.
wc_taxonomy_metadata_migrate_data() Migrate data from WC term meta to WP term meta.
wc_reorder_terms() Move a term before the a given element of its hierarchy level.
wc_set_term_order() Set the sort order of a term.
_wc_term_recount() Function for recounting product terms, ignoring hidden products.
wc_recount_after_stock_change() Recount terms after the stock amount changes.
wc_change_term_counts() Overrides the original term count for product categories and tags with the product count.
wc_get_term_product_ids() Return products in a given term, and cache value.
wc_clear_term_product_ids() When a post is updated and terms recounted (called by _update_post_term_count), clear the ids.
wc_get_product_visibility_term_ids() Get full list of product visibilty term ids.
wc_update_200_file_paths() Update file paths for 2.0
wc_update_200_permalinks() Update permalinks for 2.0
wc_update_200_subcat_display() Update sub-category display options for 2.0
wc_update_200_taxrates() Update tax rates for 2.0
wc_update_200_line_items() Update order item line items for 2.0
wc_update_200_images() Update image settings for 2.0
wc_update_200_db_version() Update DB version for 2.0
wc_update_209_brazillian_state() Update Brazilian States for 2.0.9
wc_update_209_db_version() Update DB version for 2.0.9
wc_update_210_remove_pages() Remove pages for 2.1
wc_update_210_file_paths() Update file paths to support multiple files for 2.1
wc_update_210_db_version() Update DB version for 2.1
wc_update_220_shipping() Update shipping options for 2.2
wc_update_220_order_status() Update order statuses for 2.2
wc_update_220_variations() Update variations for 2.2
wc_update_220_attributes() Update attributes for 2.2
wc_update_220_db_version() Update DB version for 2.2
wc_update_230_options() Update options for 2.3
wc_update_230_db_version() Update DB version for 2.3
wc_update_240_options() Update calc discount options for 2.4
wc_update_240_shipping_methods() Update shipping methods for 2.4
wc_update_240_api_keys() Update API keys for 2.4
wc_update_240_webhooks() Update webhooks for 2.4
wc_update_240_refunds() Update refunds for 2.4
wc_update_240_db_version() Update DB version for 2.4
wc_update_241_variations() Update variations for 2.4.1
wc_update_241_db_version() Update DB version for 2.4.1
wc_update_250_currency() Update currency settings for 2.5
wc_update_250_db_version() Update DB version for 2.5
wc_update_260_options() Update ship to countries options for 2.6
wc_update_260_termmeta() Update term meta for 2.6
wc_update_260_zones() Update zones for 2.6
wc_update_260_zone_methods() Update zone methods for 2.6
wc_update_260_refunds() Update refunds for 2.6
wc_update_260_db_version() Update DB version for 2.6
wc_update_300_webhooks() Update webhooks for 3.0
wc_update_300_comment_type_index() Add an index to the field comment_type to improve the response time of the query used by WC_Comments::wp_count_comments() to get the number of comments by type.
wc_update_300_grouped_products() Update grouped products for 3.0
wc_update_300_settings() Update shipping tax classes for 3.0
wc_update_300_product_visibility() Convert meta values into term for product visibility.
wc_update_300_db_version() Update DB Version.
wc_update_310_downloadable_products() Add an index to the downloadable product permissions table to improve performance of update_user_by_order_id.
wc_update_310_old_comments() Find old order notes and ensure they have the correct type for exclusion.
wc_update_310_db_version() Update DB Version.
wc_update_312_shop_manager_capabilities() Update shop_manager capabilities.
wc_update_312_db_version() Update DB Version.
wc_update_320_mexican_states() Update state codes for Mexico.
wc_update_320_db_version() Update DB Version.
wc_update_330_image_options() Update image settings to use new aspect ratios and widths.
wc_update_330_webhooks() Migrate webhooks from post type to CRUD.
wc_update_330_set_default_product_cat() Assign default cat to all products with no cats.
wc_update_330_product_stock_status() Update product stock status to use the new onbackorder status.
wc_update_330_clear_transients() Clear addons page transients
wc_update_330_set_paypal_sandbox_credentials() Set PayPal's sandbox credentials.
wc_update_330_db_version() Update DB Version.
wc_update_340_states() Update state codes for Ireland and BD.
wc_update_340_state() Update next state in the queue.
wc_update_340_last_active() Set last active prop for users.
wc_update_340_db_version() Update DB Version.
wc_update_343_cleanup_foreign_keys() Remove duplicate foreign keys
wc_update_343_db_version() Update DB version.
wc_update_344_recreate_roles() Recreate user roles so existing users will get the new capabilities.
wc_update_344_db_version() Update DB version.
wc_update_350_reviews_comment_type() Set the comment type to 'review' for product reviews that don't have a comment type.
wc_update_350_db_version() Update DB Version.
wc_update_352_drop_download_log_fk() Drop the fk_wc_download_log_permission_id FK as we use a new one with the table and blog prefix for MS compatability.
wc_update_354_modify_shop_manager_caps() Remove edit_user capabilities from shop managers and use "translated" capabilities instead.
wc_update_354_db_version() Update DB Version.
wc_update_360_product_lookup_tables() Update product lookup tables in bulk.
wc_update_360_term_meta() Renames ordering meta to be consistent across taxonomies.
wc_update_360_downloadable_product_permissions_index() Add new user_order_remaining_expires to speed up user download permission fetching.
wc_update_360_db_version() Update DB Version.
wc_update_370_tax_rate_classes() Put tax classes into a DB table.
wc_update_370_mro_std_currency() Update currency settings for 3.7.0
wc_update_370_db_version() Update DB Version.
wc_update_390_move_maxmind_database() We've moved the MaxMind database to a new location, as per the TOS' requirement that the database not be publicly accessible.
wc_update_390_change_geolocation_database_update_cron() So that we can best meet MaxMind's TOS, the geolocation database update cron should run once per 15 days.
wc_update_390_db_version() Update DB version.
wc_update_400_increase_size_of_column() Increase column size
wc_update_400_reset_action_scheduler_migration_status() Reset ActionScheduler migration status. Needs AS >= 3.0 shipped with WC >= 4.0.
wc_update_400_db_version() Update DB version.
wc_update_440_insert_attribute_terms_for_variable_products() Register attributes as terms for variable products, in increments of 100 products.
wc_update_440_db_version() Update DB version.
wc_disable_admin_bar() Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from seeing the admin bar.
wc_create_new_customer() Create a new customer.
wc_create_new_customer_username() Create a unique username for a new customer.
wc_set_customer_auth_cookie() Login a customer (set auth cookie and set global user object).
wc_update_new_customer_past_orders() Get past orders (by email) and update them.
wc_paying_customer() Order payment completed - This is a paying customer.
wc_customer_bought_product() Checks if a user (by email or ID or both) has bought an item.
wc_current_user_has_role() Checks if the current user has a role.
wc_user_has_role() Checks if a user has a role.
wc_customer_has_capability() Checks if a user has a certain capability.
wc_shop_manager_has_capability() Safe way of allowing shop managers restricted capabilities that will remove access to the capabilities if WooCommerce is deactivated.
wc_modify_editable_roles() Modify the list of editable roles to prevent non-admin adding admin users.
wc_modify_map_meta_cap() Modify capabilities to prevent non-admin users editing admin users.
wc_get_customer_download_permissions() Get customer download permissions from the database.
wc_get_customer_available_downloads() Get customer available downloads.
wc_get_customer_total_spent() Get total spent by customer.
wc_get_customer_order_count() Get total orders by customer.
wc_reset_order_customer_id_on_deleted_user() Reset _customer_user on orders when a user is deleted.
wc_review_is_from_verified_owner() Get review verification status.
wc_disable_author_archives_for_customers() Disable author archives for customers.
wc_update_profile_last_update_time() Hooks into the `profile_update` hook to set the user last updated timestamp.
wc_meta_update_last_update_time() Hooks into the update user meta function to set the user last updated timestamp.
wc_set_user_last_update_time() Sets a user's "last update" time to the current timestamp.
wc_get_customer_saved_methods_list() Get customer saved payment methods list.
wc_get_customer_last_order() Get info about customer's last order.
wc_user_search_columns() Add support for searching by display_name.
wc_delete_user_data() When a user is deleted in WordPress, delete corresponding WooCommerce data.
wc_maybe_store_user_agent() Store user agents. Used for tracker.
wc_user_logged_in() Update logic triggered on login.
wc_current_user_is_active() Update when the user was last active.
wc_update_user_last_active() Set the user last active timestamp to now.
wc_translate_user_roles() Translate WC roles using the woocommerce textdomain.
wc_webhook_execute_queue() Process the web hooks at the end of the request.
wc_webhook_process_delivery() Process webhook delivery.
wc_deliver_webhook_async() Wrapper function to execute the `woocommerce_deliver_webhook_async` cron.
wc_is_webhook_valid_topic() Check if the given topic is a valid webhook topic, a topic is valid if:
wc_is_webhook_valid_status() Check if given status is a valid webhook status.
wc_get_webhook_statuses() Get Webhook statuses.
wc_load_webhooks() Load webhooks.
wc_get_webhook() Get webhook.
wc_get_webhook_rest_api_versions() Get webhoook REST API versions.
wc_register_widgets() Register Widgets.

Functions

wc_lostpassword_url()

Returns the url to the lost password endpoint url.

wc_lostpassword_url( [ $default_url : string = '' ] ) : string
Parameters
$default_url : string = ''

Default lost password URL.

Return values
string

wc_customer_edit_account_url()

Get the link to the edit account details page.

wc_customer_edit_account_url( ) : string
Return values
string

wc_edit_address_i18n()

Get the edit address slug translation.

wc_edit_address_i18n( $id : string [, $flip : bool = false ] ) : string
Parameters
$id : string

Address ID.

$flip : bool = false

Flip the array to make it possible to retrieve the values ​​from both sides.

Return values
string

Address slug i18n.

wc_get_account_menu_items()

Get My Account menu items.

wc_get_account_menu_items( ) : array
Tags
since
Return values
array

wc_get_account_menu_item_classes()

Get account menu item classes.

wc_get_account_menu_item_classes( $endpoint : string ) : string
Parameters
$endpoint : string

Endpoint.

Tags
since
Return values
string

wc_get_account_endpoint_url()

Get account endpoint URL.

wc_get_account_endpoint_url( $endpoint : string ) : string
Parameters
$endpoint : string

Endpoint.

Tags
since
Return values
string

wc_get_account_orders_columns()

Get My Account > Orders columns.

wc_get_account_orders_columns( ) : array
Tags
since
Return values
array

wc_get_account_downloads_columns()

Get My Account > Downloads columns.

wc_get_account_downloads_columns( ) : array
Tags
since
Return values
array

wc_get_account_payment_methods_columns()

Get My Account > Payment methods columns.

wc_get_account_payment_methods_columns( ) : array
Tags
since
Return values
array

wc_get_account_payment_methods_types()

Get My Account > Payment methods types

wc_get_account_payment_methods_types( ) : array
Tags
since
Return values
array

wc_get_account_orders_actions()

Get account orders actions.

wc_get_account_orders_actions( $order : int|WC_Order ) : array
Parameters
$order : int|WC_Order

Order instance or ID.

Tags
since
Return values
array

wc_get_account_formatted_address()

Get account formatted address.

wc_get_account_formatted_address( [ $address_type : string = 'billing' ] , $customer_id : int ) : string
Parameters
$address_type : string = 'billing'

Address type. Accepts: 'billing' or 'shipping'. Default to 'billing'.

$customer_id : int

Customer ID. Default to 0.

Tags
since
Return values
string

wc_get_account_saved_payment_methods_list()

Returns an array of a user's saved payments list for output on the account tab.

wc_get_account_saved_payment_methods_list( $list : array , $customer_id : int ) : array
Parameters
$list : array

List of payment methods passed from wc_get_customer_saved_methods_list().

$customer_id : int

The customer to fetch payment methods for.

Tags
since
Return values
array

Filtered list of customers payment methods.

wc_get_account_saved_payment_methods_list_item_cc()

Controls the output for credit cards on the my account page.

wc_get_account_saved_payment_methods_list_item_cc( $item : array , $payment_token : WC_Payment_Token ) : array
Parameters
$item : array

Individual list item from woocommerce_saved_payment_methods_list.

$payment_token : WC_Payment_Token

The payment token associated with this method entry.

Tags
since
Return values
array

Filtered item.

wc_get_account_saved_payment_methods_list_item_echeck()

Controls the output for eChecks on the my account page.

wc_get_account_saved_payment_methods_list_item_echeck( $item : array , $payment_token : WC_Payment_Token ) : array
Parameters
$item : array

Individual list item from woocommerce_saved_payment_methods_list.

$payment_token : WC_Payment_Token

The payment token associated with this method entry.

Tags
since
Return values
array

Filtered item.

wc_get_text_attributes()

Gets text attributes from a string.

wc_get_text_attributes( $raw_attributes : string ) : array
Parameters
$raw_attributes : string

Raw attributes.

Tags
since
Return values
array

wc_get_text_attributes_filter_callback()

See if an attribute is actually valid.

wc_get_text_attributes_filter_callback( $value : string ) : bool
Parameters
$value : string

Value.

Tags
since
Return values
bool

wc_implode_text_attributes()

Implode an array of attributes using WC_DELIMITER.

wc_implode_text_attributes( $attributes : array ) : string
Parameters
$attributes : array

Attributes list.

Tags
since
Return values
string

wc_get_attribute_taxonomies()

Get attribute taxonomies.

wc_get_attribute_taxonomies( ) : array
Return values
array

of objects, @since 3.6.0 these are also indexed by ID.

wc_get_attribute_taxonomy_ids()

Get (cached) attribute taxonomy ID and name pairs.

wc_get_attribute_taxonomy_ids( ) : array
Tags
since
Return values
array

wc_get_attribute_taxonomy_labels()

Get (cached) attribute taxonomy label and name pairs.

wc_get_attribute_taxonomy_labels( ) : array
Tags
since
Return values
array

wc_attribute_taxonomy_name()

Get a product attribute name.

wc_attribute_taxonomy_name( $attribute_name : string ) : string
Parameters
$attribute_name : string

Attribute name.

Return values
string

wc_variation_attribute_name()

Get the attribute name used when storing values in post meta.

wc_variation_attribute_name( $attribute_name : string ) : string
Parameters
$attribute_name : string

Attribute name.

Tags
since
Return values
string

wc_attribute_taxonomy_name_by_id()

Get a product attribute name by ID.

wc_attribute_taxonomy_name_by_id( $attribute_id : int ) : string
Parameters
$attribute_id : int

Attribute ID.

Tags
since
Return values
string

Return an empty string if attribute doesn't exist.

wc_attribute_taxonomy_id_by_name()

Get a product attribute ID by name.

wc_attribute_taxonomy_id_by_name( $name : string ) : int
Parameters
$name : string

Attribute name.

Tags
since
Return values
int

wc_attribute_label()

Get a product attributes label.

wc_attribute_label( $name : string [, $product : WC_Product = '' ] ) : string
Parameters
$name : string

Attribute name.

$product : WC_Product = ''

Product data.

Return values
string

wc_attribute_orderby()

Get a product attributes orderby setting.

wc_attribute_orderby( $name : string ) : string
Parameters
$name : string

Attribute name.

Return values
string

wc_get_attribute_taxonomy_names()

Get an array of product attribute taxonomies.

wc_get_attribute_taxonomy_names( ) : array
Return values
array

wc_get_attribute_types()

Get attribute types.

wc_get_attribute_types( ) : array
Tags
since
Return values
array

wc_has_custom_attribute_types()

Check if there are custom attribute types.

wc_has_custom_attribute_types( ) : bool
Tags
since
Return values
bool

True if there are custom types, otherwise false.

wc_get_attribute_type_label()

Get attribute type label.

wc_get_attribute_type_label( $type : string ) : string
Parameters
$type : string

Attribute type slug.

Tags
since
Return values
string

wc_is_attribute_in_product_name()

Check if an attribute is included in the attributes area of a variation name.

wc_is_attribute_in_product_name( $attribute : string , $name : string ) : bool
Parameters
$attribute : string

Attribute value to check for.

$name : string

Product name to check in.

Tags
since
Return values
bool

wc_array_filter_default_attributes()

Callback for array filter to get default attributes. Will allow for '0' string values, but regard all other class PHP FALSE equivalents normally.

wc_array_filter_default_attributes( $attribute : mixed ) : bool
Parameters
$attribute : mixed

Attribute being considered for exclusion from parent array.

Tags
since
Return values
bool

wc_get_attribute()

Get attribute data by ID.

wc_get_attribute( $id : int ) : stdClass|null
Parameters
$id : int

Attribute ID.

Tags
since
Return values
stdClass|null

wc_create_attribute()

Create attribute.

wc_create_attribute( $args : array ) : int|WP_Error
Parameters
$args : array

Attribute arguments { Array of attribute parameters.

@type int    $id           Unique identifier, used to update an attribute.
@type string $name         Attribute name. Always required.
@type string $slug         Attribute alphanumeric identifier.
@type string $type         Type of attribute.
                           Core by default accepts: 'select' and 'text'.
                           Default to 'select'.
@type string $order_by     Sort order.
                           Accepts: 'menu_order', 'name', 'name_num' and 'id'.
                           Default to 'menu_order'.
@type bool   $has_archives Enable or disable attribute archives. False by default.

}

Tags
since
Return values
int|WP_Error

wc_update_attribute()

Update an attribute.

wc_update_attribute( $id : int , $args : array ) : int|WP_Error

For available args see wc_create_attribute().

Parameters
$id : int

Attribute ID.

$args : array

Attribute arguments.

Tags
since
Return values
int|WP_Error

wc_delete_attribute()

Delete attribute by ID.

wc_delete_attribute( $id : int ) : bool
Parameters
$id : int

Attribute ID.

Tags
since
Return values
bool

wc_attribute_taxonomy_slug()

Get an unprefixed product attribute name.

wc_attribute_taxonomy_slug( $attribute_name : string ) : string
Parameters
$attribute_name : string

Attribute name.

Tags
since
Return values
string

wc_protected_product_add_to_cart()

Prevent password protected products being added to the cart.

wc_protected_product_add_to_cart( $passed : bool , $product_id : int ) : bool
Parameters
$passed : bool

Validation.

$product_id : int

Product ID.

Return values
bool

wc_empty_cart()

Clears the cart session when called.

wc_empty_cart( ) : mixed
Return values
mixed

wc_load_persistent_cart()

Load the persistent cart.

wc_load_persistent_cart( $user_login : string , $user : WP_User ) : mixed
Parameters
$user_login : string

User login.

$user : WP_User

User data.

Tags
deprecated
Return values
mixed

wc_get_raw_referer()

Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.

wc_get_raw_referer( ) : string|false

Do not use for redirects, use \wp_get_referer() instead.

Tags
since
Return values
string|false

Referer URL on success, false on failure.

wc_add_to_cart_message()

Add to cart messages.

wc_add_to_cart_message( $products : int|array [, $show_qty : bool = false ] [, $return : bool = false ] ) : mixed
Parameters
$products : int|array

Product ID list or single product ID.

$show_qty : bool = false

Should qty's be shown? Added in 2.6.0.

$return : bool = false

Return message rather than add it.

Return values
mixed

wc_format_list_of_items()

Comma separate a list of item names, and replace final comma with 'and'.

wc_format_list_of_items( $items : array ) : string
Parameters
$items : array

Cart items.

Return values
string

wc_clear_cart_after_payment()

Clear cart after payment.

wc_clear_cart_after_payment( ) : mixed
Return values
mixed

wc_cart_totals_subtotal_html()

Get the subtotal.

wc_cart_totals_subtotal_html( ) : mixed
Return values
mixed

wc_cart_totals_shipping_html()

Get shipping methods.

wc_cart_totals_shipping_html( ) : mixed
Return values
mixed

wc_cart_totals_taxes_total_html()

Get taxes total.

wc_cart_totals_taxes_total_html( ) : mixed
Return values
mixed

wc_cart_totals_coupon_label()

Get a coupon label.

wc_cart_totals_coupon_label( $coupon : string|WC_Coupon [, $echo : bool = true ] ) : string
Parameters
$coupon : string|WC_Coupon

Coupon data or code.

$echo : bool = true

Echo or return.

Return values
string

wc_cart_totals_coupon_html()

Get coupon display HTML.

wc_cart_totals_coupon_html( $coupon : string|WC_Coupon ) : mixed
Parameters
$coupon : string|WC_Coupon

Coupon data or code.

Return values
mixed

wc_cart_totals_order_total_html()

Get order total html including inc tax if needed.

wc_cart_totals_order_total_html( ) : mixed
Return values
mixed

wc_cart_totals_fee_html()

Get the fee value.

wc_cart_totals_fee_html( $fee : object ) : mixed
Parameters
$fee : object

Fee data.

Return values
mixed

wc_cart_totals_shipping_method_label()

Get a shipping methods full label including price.

wc_cart_totals_shipping_method_label( $method : WC_Shipping_Rate ) : string
Parameters
$method : WC_Shipping_Rate

Shipping method rate data.

Return values
string

wc_cart_round_discount()

Round discount.

wc_cart_round_discount( $value : float , $precision : int ) : float
Parameters
$value : float

Amount to round.

$precision : int

DP to round.

Return values
float

wc_get_chosen_shipping_method_ids()

Gets chosen shipping method IDs from chosen_shipping_methods session, without instance IDs.

wc_get_chosen_shipping_method_ids( ) : string[]
Tags
since
Return values
string[]

wc_get_chosen_shipping_method_for_package()

Get chosen method for package from session.

wc_get_chosen_shipping_method_for_package( $key : int , $package : array ) : string|bool
Parameters
$key : int

Key of package.

$package : array

Package data array.

Tags
since
Return values
string|bool

wc_get_default_shipping_method_for_package()

Choose the default method for a package.

wc_get_default_shipping_method_for_package( $key : int , $package : array , $chosen_method : string ) : string
Parameters
$key : int

Key of package.

$package : array

Package data array.

$chosen_method : string

Chosen method id.

Tags
since
Return values
string

wc_shipping_methods_have_changed()

See if the methods have changed since the last request.

wc_shipping_methods_have_changed( $key : int , $package : array ) : bool
Parameters
$key : int

Key of package.

$package : array

Package data array.

Tags
since
Return values
bool

wc_get_cart_item_data_hash()

Gets a hash of important product data that when changed should cause cart items to be invalidated.

wc_get_cart_item_data_hash( $product : WC_Product ) : string

The woocommerce_cart_item_data_to_validate filter can be used to add custom properties.

Parameters
$product : WC_Product

Product object.

Return values
string

is_woocommerce()

Is_woocommerce - Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included).

is_woocommerce( ) : bool
Return values
bool

is_shop()

Is_shop - Returns true when viewing the product type archive (shop).

is_shop( ) : bool
Return values
bool

is_product_taxonomy()

Is_product_taxonomy - Returns true when viewing a product taxonomy archive.

is_product_taxonomy( ) : bool
Return values
bool

is_product_category()

Is_product_category - Returns true when viewing a product category.

is_product_category( [ $term : string = '' ] ) : bool
Parameters
$term : string = ''

(default: '') The term slug your checking for. Leave blank to return true on any.

Return values
bool

is_product_tag()

Is_product_tag - Returns true when viewing a product tag.

is_product_tag( [ $term : string = '' ] ) : bool
Parameters
$term : string = ''

(default: '') The term slug your checking for. Leave blank to return true on any.

Return values
bool

is_product()

Is_product - Returns true when viewing a single product.

is_product( ) : bool
Return values
bool

is_checkout()

Is_checkout - Returns true when viewing the checkout page.

is_checkout( ) : bool
Return values
bool

is_checkout_pay_page()

Is_checkout_pay - Returns true when viewing the checkout's pay page.

is_checkout_pay_page( ) : bool
Return values
bool

is_wc_endpoint_url()

Is_wc_endpoint_url - Check if an endpoint is showing.

is_wc_endpoint_url( [ $endpoint : string|false = false ] ) : bool
Parameters
$endpoint : string|false = false

Whether endpoint.

Return values
bool

is_account_page()

Is_account_page - Returns true when viewing an account page.

is_account_page( ) : bool
Return values
bool

is_view_order_page()

Is_view_order_page - Returns true when on the view order page.

is_view_order_page( ) : bool
Return values
bool

is_edit_account_page()

Check for edit account page.

is_edit_account_page( ) : bool

Returns true when viewing the edit account page.

Tags
since
Return values
bool

is_order_received_page()

Is_order_received_page - Returns true when viewing the order received page.

is_order_received_page( ) : bool
Return values
bool

is_add_payment_method_page()

Is_add_payment_method_page - Returns true when viewing the add payment method page.

is_add_payment_method_page( ) : bool
Return values
bool

is_lost_password_page()

Is_lost_password_page - Returns true when viewing the lost password page.

is_lost_password_page( ) : bool
Return values
bool

is_ajax()

Is_ajax - Returns true when the page is loaded via ajax.

is_ajax( ) : bool
Return values
bool

is_store_notice_showing()

Is_store_notice_showing - Returns true when store notice is active.

is_store_notice_showing( ) : bool
Return values
bool

is_filtered()

Is_filtered - Returns true when filtering products using layered nav or price sliders.

is_filtered( ) : bool
Return values
bool

taxonomy_is_product_attribute()

Returns true when the passed taxonomy name is a product attribute.

taxonomy_is_product_attribute( $name : string ) : bool
Parameters
$name : string

of the attribute.

Tags
uses

$wc_product_attributes global which stores taxonomy names upon registration

Return values
bool

meta_is_product_attribute()

Returns true when the passed meta name is a product attribute.

meta_is_product_attribute( $name : string , $value : string , $product_id : int ) : bool
Parameters
$name : string

of the attribute.

$value : string

of the attribute.

$product_id : int

to check for attribute.

Return values
bool

wc_prices_include_tax()

Are prices inclusive of tax?

wc_prices_include_tax( ) : bool
Return values
bool

wc_is_valid_url()

Simple check for validating a URL, it must start with http:// or https://.

wc_is_valid_url( $url : string ) : bool

and pass FILTER_VALIDATE_URL validation.

Parameters
$url : string

to check.

Return values
bool

wc_site_is_https()

Check if the home URL is https. If it is, we don't need to do things such as 'force ssl'.

wc_site_is_https( ) : bool
Tags
since
Return values
bool

wc_checkout_is_https()

Check if the checkout is configured for https. Look at options, WP HTTPS plugin, or the permalink itself.

wc_checkout_is_https( ) : bool
Tags
since
Return values
bool

wc_post_content_has_shortcode()

Checks whether the content passed contains a specific short code.

wc_post_content_has_shortcode( [ $tag : string = '' ] ) : bool
Parameters
$tag : string = ''

Shortcode tag to check.

Return values
bool

wc_reviews_enabled()

Check if reviews are enabled.

wc_reviews_enabled( ) : bool
Tags
since
Return values
bool

wc_review_ratings_enabled()

Check if reviews ratings are enabled.

wc_review_ratings_enabled( ) : bool
Tags
since
Return values
bool

wc_review_ratings_required()

Check if review ratings are required.

wc_review_ratings_required( ) : bool
Tags
since
Return values
bool

wc_is_file_valid_csv()

Check if a CSV file is valid.

wc_is_file_valid_csv( $file : string [, $check_path : bool = true ] ) : bool
Parameters
$file : string

File name.

$check_path : bool = true

If should check for the path.

Tags
since
Return values
bool

wc_get_coupon_types()

Get coupon types.

wc_get_coupon_types( ) : array
Return values
array

wc_get_coupon_type()

Get a coupon type's name.

wc_get_coupon_type( [ $type : string = '' ] ) : string
Parameters
$type : string = ''

Coupon type.

Return values
string

wc_get_product_coupon_types()

Coupon types that apply to individual products. Controls which validation rules will apply.

wc_get_product_coupon_types( ) : array
Tags
since
Return values
array

wc_get_cart_coupon_types()

Coupon types that apply to the cart as a whole. Controls which validation rules will apply.

wc_get_cart_coupon_types( ) : array
Tags
since
Return values
array

wc_coupons_enabled()

Check if coupons are enabled.

wc_coupons_enabled( ) : bool

Filterable.

Tags
since
Return values
bool

wc_get_coupon_code_by_id()

Get coupon code by ID.

wc_get_coupon_code_by_id( $id : int ) : string
Parameters
$id : int

Coupon ID.

Tags
since
Return values
string

wc_get_coupon_id_by_code()

Get coupon code by ID.

wc_get_coupon_id_by_code( $code : string , $exclude : int ) : int
Parameters
$code : string

Coupon code.

$exclude : int

Used to exclude an ID from the check if you're checking existence.

Tags
since
Return values
int

wc_string_to_bool()

Converts a string (e.g. 'yes' or 'no') to a bool.

wc_string_to_bool( $string : string ) : bool
Parameters
$string : string

String to convert.

Tags
since
Return values
bool

wc_bool_to_string()

Converts a bool to a 'yes' or 'no'.

wc_bool_to_string( $bool : bool ) : string
Parameters
$bool : bool

String to convert.

Tags
since
Return values
string

wc_string_to_array()

Explode a string into an array by $delimiter and remove empty values.

wc_string_to_array( $string : string [, $delimiter : string = ',' ] ) : array
Parameters
$string : string

String to convert.

$delimiter : string = ','

Delimiter, defaults to ','.

Tags
since
Return values
array

wc_sanitize_taxonomy_name()

Sanitize taxonomy names. Slug format (no spaces, lowercase).

wc_sanitize_taxonomy_name( $taxonomy : string ) : string

Urldecode is used to reverse munging of UTF8 characters.

Parameters
$taxonomy : string

Taxonomy name.

Return values
string

wc_sanitize_permalink()

Sanitize permalink values before insertion into DB.

wc_sanitize_permalink( $value : string ) : string

Cannot use wc_clean because it sometimes strips % chars and breaks the user's setting.

Parameters
$value : string

Permalink.

Tags
since
Return values
string

wc_get_filename_from_url()

Gets the filename part of a download URL.

wc_get_filename_from_url( $file_url : string ) : string
Parameters
$file_url : string

File URL.

Return values
string

wc_get_dimension()

Normalise dimensions, unify to cm then convert to wanted unit value.

wc_get_dimension( $dimension : int|float , $to_unit : string [, $from_unit : string = '' ] ) : float

Usage: wc_get_dimension( 55, 'in' ); wc_get_dimension( 55, 'in', 'm' );

Parameters
$dimension : int|float

Dimension.

$to_unit : string

Unit to convert to. Options: 'in', 'm', 'cm', 'm'.

$from_unit : string = ''

Unit to convert from. Defaults to ''. Options: 'in', 'm', 'cm', 'm'.

Return values
float

wc_get_weight()

Normalise weights, unify to kg then convert to wanted unit value.

wc_get_weight( $weight : int|float , $to_unit : string [, $from_unit : string = '' ] ) : float

Usage: wc_get_weight(55, 'kg'); wc_get_weight(55, 'kg', 'lbs');

Parameters
$weight : int|float

Weight.

$to_unit : string

Unit to convert to. Options: 'g', 'kg', 'lbs', 'oz'.

$from_unit : string = ''

Unit to convert from. Defaults to ''. Options: 'g', 'kg', 'lbs', 'oz'.

Return values
float

wc_trim_zeros()

Trim trailing zeros off prices.

wc_trim_zeros( $price : string|float|int ) : string
Parameters
$price : string|float|int

Price.

Return values
string

wc_round_tax_total()

Round a tax amount.

wc_round_tax_total( $value : float [, $precision : int = null ] ) : float
Parameters
$value : float

Amount to round.

$precision : int = null

DP to round. Defaults to wc_get_price_decimals.

Return values
float

wc_legacy_round_half_down()

Round half down in PHP 5.2.

wc_legacy_round_half_down( $value : float , $precision : int ) : float
Parameters
$value : float

Value to round.

$precision : int

Precision to round down to.

Tags
since
Return values
float

wc_format_refund_total()

Make a refund total negative.

wc_format_refund_total( $amount : float ) : float
Parameters
$amount : float

Refunded amount.

Return values
float

wc_format_decimal()

Format decimal numbers ready for DB storage.

wc_format_decimal( $number : float|string [, $dp : mixed = false ] [, $trim_zeros : bool = false ] ) : string

Sanitize, remove decimals, and optionally round + trim off zeros.

This function does not remove thousands - this should be done before passing a value to the function.

Parameters
$number : float|string

Expects either a float or a string with a decimal separator only (no thousands).

$dp : mixed = false

number Number of decimal points to use, blank to use woocommerce_price_num_decimals, or false to avoid all rounding.

$trim_zeros : bool = false

From end of string.

Return values
string

wc_float_to_string()

Convert a float to a string without locale formatting which PHP adds when changing floats to strings.

wc_float_to_string( $float : float ) : string
Parameters
$float : float

Float value to format.

Return values
string

wc_format_localized_price()

Format a price with WC Currency Locale settings.

wc_format_localized_price( $value : string ) : string
Parameters
$value : string

Price to localize.

Return values
string

wc_format_localized_decimal()

Format a decimal with PHP Locale settings.

wc_format_localized_decimal( $value : string ) : string
Parameters
$value : string

Decimal to localize.

Return values
string

wc_format_coupon_code()

Format a coupon code.

wc_format_coupon_code( $value : string ) : string
Parameters
$value : string

Coupon code to format.

Tags
since
Return values
string

wc_sanitize_coupon_code()

Sanitize a coupon code.

wc_sanitize_coupon_code( $value : string ) : string

Uses sanitize_post_field since coupon codes are stored as post_titles - the sanitization and escaping must match.

Parameters
$value : string

Coupon code to format.

Tags
since
Return values
string

wc_clean()

Clean variables using sanitize_text_field. Arrays are cleaned recursively.

wc_clean( $var : string|array ) : string|array

Non-scalar values are ignored.

Parameters
$var : string|array

Data to sanitize.

Return values
string|array

wc_check_invalid_utf8()

Function wp_check_invalid_utf8 with recursive array support.

wc_check_invalid_utf8( $var : string|array ) : string|array
Parameters
$var : string|array

Data to sanitize.

Return values
string|array

wc_sanitize_textarea()

Run wc_clean over posted textarea but maintain line breaks.

wc_sanitize_textarea( $var : string ) : string
Parameters
$var : string

Data to sanitize.

Tags
since
Return values
string

wc_sanitize_tooltip()

Sanitize a string destined to be a tooltip.

wc_sanitize_tooltip( $var : string ) : string
Parameters
$var : string

Data to sanitize.

Tags
since

Tooltips are encoded with htmlspecialchars to prevent XSS. Should not be used in conjunction with esc_attr()

Return values
string

wc_array_overlay()

Merge two arrays.

wc_array_overlay( $a1 : array , $a2 : array ) : array
Parameters
$a1 : array

First array to merge.

$a2 : array

Second array to merge.

Return values
array

wc_stock_amount()

Formats a stock amount by running it through a filter.

wc_stock_amount( $amount : int|float ) : int|float
Parameters
$amount : int|float

Stock amount.

Return values
int|float

get_woocommerce_price_format()

Get the price format depending on the currency position.

get_woocommerce_price_format( ) : string
Return values
string

wc_get_price_thousand_separator()

Return the thousand separator for prices.

wc_get_price_thousand_separator( ) : string
Tags
since
Return values
string

wc_get_price_decimal_separator()

Return the decimal separator for prices.

wc_get_price_decimal_separator( ) : string
Tags
since
Return values
string

wc_get_price_decimals()

Return the number of decimals after the decimal point.

wc_get_price_decimals( ) : int
Tags
since
Return values
int

wc_price()

Format the price with a currency symbol.

wc_price( $price : float [, $args : array = array() ] ) : string
Parameters
$price : float

Raw price.

$args : array = array()

Arguments to format a price { Array of arguments. Defaults to empty array.

@type bool   $ex_tax_label       Adds exclude tax label.
                                 Defaults to false.
@type string $currency           Currency code.
                                 Defaults to empty string (Use the result from get_woocommerce_currency()).
@type string $decimal_separator  Decimal separator.
                                 Defaults the result of wc_get_price_decimal_separator().
@type string $thousand_separator Thousand separator.
                                 Defaults the result of wc_get_price_thousand_separator().
@type string $decimals           Number of decimals.
                                 Defaults the result of wc_get_price_decimals().
@type string $price_format       Price format depending on the currency position.
                                 Defaults the result of get_woocommerce_price_format().

}

Return values
string

wc_let_to_num()

Notation to numbers.

wc_let_to_num( $size : string ) : int

This function transforms the php.ini notation for numbers (like '2M') to an integer.

Parameters
$size : string

Size value.

Return values
int

wc_date_format()

WooCommerce Date Format - Allows to change date format for everything WooCommerce.

wc_date_format( ) : string
Return values
string

wc_time_format()

WooCommerce Time Format - Allows to change time format for everything WooCommerce.

wc_time_format( ) : string
Return values
string

wc_string_to_timestamp()

Convert mysql datetime to PHP timestamp, forcing UTC. Wrapper for strtotime.

wc_string_to_timestamp( $time_string : string [, $from_timestamp : int|null = null ] ) : int

Based on wcs_strtotime_dark_knight() from WC Subscriptions by Prospress.

Parameters
$time_string : string

Time string.

$from_timestamp : int|null = null

Timestamp to convert from.

Tags
since
Return values
int

wc_timezone_offset()

Get timezone offset in seconds.

wc_timezone_offset( ) : float
Tags
since
Return values
float

wc_flatten_meta_callback()

Callback which can flatten post meta (gets the first value if it's an array).

wc_flatten_meta_callback( $value : array ) : mixed
Parameters
$value : array

Value to flatten.

Tags
since
Return values
mixed

wc_rgb_from_hex()

Convert RGB to HEX.

wc_rgb_from_hex( $color : mixed ) : array
Parameters
$color : mixed

Color.

Return values
array

wc_hex_darker()

Make HEX color darker.

wc_hex_darker( $color : mixed [, $factor : int = 30 ] ) : string
Parameters
$color : mixed

Color.

$factor : int = 30

Darker factor. Defaults to 30.

Return values
string

wc_hex_lighter()

Make HEX color lighter.

wc_hex_lighter( $color : mixed [, $factor : int = 30 ] ) : string
Parameters
$color : mixed

Color.

$factor : int = 30

Lighter factor. Defaults to 30.

Return values
string

wc_hex_is_light()

Determine whether a hex color is light.

wc_hex_is_light( $color : mixed ) : bool
Parameters
$color : mixed

Color.

Return values
bool

True if a light color.

wc_light_or_dark()

Detect if we should use a light or dark color on a background color.

wc_light_or_dark( $color : mixed [, $dark : string = '#000000' ] [, $light : string = '#FFFFFF' ] ) : string
Parameters
$color : mixed

Color.

$dark : string = '#000000'

Darkest reference. Defaults to '#000000'.

$light : string = '#FFFFFF'

Lightest reference. Defaults to '#FFFFFF'.

Return values
string

wc_format_hex()

Format string as hex.

wc_format_hex( $hex : string ) : string|null
Parameters
$hex : string

HEX color.

Return values
string|null

wc_format_postcode()

Format the postcode according to the country and length of the postcode.

wc_format_postcode( $postcode : string , $country : string ) : string
Parameters
$postcode : string

Unformatted postcode.

$country : string

Base country.

Return values
string

wc_normalize_postcode()

Normalize postcodes.

wc_normalize_postcode( $postcode : string ) : string

Remove spaces and convert characters to uppercase.

Parameters
$postcode : string

Postcode.

Tags
since
Return values
string

wc_format_phone_number()

Format phone numbers.

wc_format_phone_number( $phone : string ) : string
Parameters
$phone : string

Phone number.

Return values
string

wc_sanitize_phone_number()

Sanitize phone number.

wc_sanitize_phone_number( $phone : string ) : string

Allows only numbers and "+" (plus sign).

Parameters
$phone : string

Phone number.

Tags
since
Return values
string

wc_strtoupper()

Wrapper for mb_strtoupper which see's if supported first.

wc_strtoupper( $string : string ) : string
Parameters
$string : string

String to format.

Tags
since
Return values
string

wc_strtolower()

Make a string lowercase.

wc_strtolower( $string : string ) : string

Try to use mb_strtolower() when available.

Parameters
$string : string

String to format.

Tags
since
Return values
string

wc_trim_string()

Trim a string and append a suffix.

wc_trim_string( $string : string [, $chars : int = 200 ] [, $suffix : string = '...' ] ) : string
Parameters
$string : string

String to trim.

$chars : int = 200

Amount of characters. Defaults to 200.

$suffix : string = '...'

Suffix. Defaults to '...'.

Return values
string

wc_format_content()

Format content to display shortcodes.

wc_format_content( $raw_string : string ) : string
Parameters
$raw_string : string

Raw string.

Tags
since
Return values
string

wc_format_product_short_description()

Format product short description.

wc_format_product_short_description( $content : string ) : string

Adds support for Jetpack Markdown.

Parameters
$content : string

Product short description.

Tags
codeCoverageIgnore
since
Return values
string

wc_format_option_price_separators()

Formats curency symbols when saved in settings.

wc_format_option_price_separators( $value : string , $option : array , $raw_value : string ) : string
Parameters
$value : string

Option value.

$option : array

Option name.

$raw_value : string

Raw value.

Tags
codeCoverageIgnore
Return values
string

wc_format_option_price_num_decimals()

Formats decimals when saved in settings.

wc_format_option_price_num_decimals( $value : string , $option : array , $raw_value : string ) : string
Parameters
$value : string

Option value.

$option : array

Option name.

$raw_value : string

Raw value.

Tags
codeCoverageIgnore
Return values
string

wc_format_option_hold_stock_minutes()

Formats hold stock option and sets cron event up.

wc_format_option_hold_stock_minutes( $value : string , $option : array , $raw_value : string ) : string
Parameters
$value : string

Option value.

$option : array

Option name.

$raw_value : string

Raw value.

Tags
codeCoverageIgnore
Return values
string

wc_sanitize_term_text_based()

Sanitize terms from an attribute text based.

wc_sanitize_term_text_based( $term : string ) : string
Parameters
$term : string

Term value.

Tags
since
Return values
string

wc_make_numeric_postcode()

Make numeric postcode.

wc_make_numeric_postcode( $postcode : string ) : string

Converts letters to numbers so we can do a simple range check on postcodes. E.g. PE30 becomes 16050300 (P = 16, E = 05, 3 = 03, 0 = 00)

Parameters
$postcode : string

Regular postcode.

Tags
since
Return values
string

wc_format_stock_for_display()

Format the stock amount ready for display based on settings.

wc_format_stock_for_display( $product : WC_Product ) : string
Parameters
$product : WC_Product

Product object for which the stock you need to format.

Tags
since
Return values
string

wc_format_stock_quantity_for_display()

Format the stock quantity ready for display.

wc_format_stock_quantity_for_display( $stock_quantity : int , $product : WC_Product ) : string
Parameters
$stock_quantity : int

Stock quantity.

$product : WC_Product

Product instance so that we can pass through the filters.

Tags
since
Return values
string

wc_format_sale_price()

Format a sale price for display.

wc_format_sale_price( $regular_price : string , $sale_price : string ) : string
Parameters
$regular_price : string

Regular price.

$sale_price : string

Sale price.

Tags
since
Return values
string

wc_format_price_range()

Format a price range for display.

wc_format_price_range( $from : string , $to : string ) : string
Parameters
$from : string

Price from.

$to : string

Price to.

Return values
string

wc_format_weight()

Format a weight for display.

wc_format_weight( $weight : float ) : string
Parameters
$weight : float

Weight.

Tags
since
Return values
string

wc_format_dimensions()

Format dimensions for display.

wc_format_dimensions( $dimensions : array ) : string
Parameters
$dimensions : array

Array of dimensions.

Tags
since
Return values
string

wc_format_datetime()

Format a date for output.

wc_format_datetime( $date : WC_DateTime [, $format : string = '' ] ) : string
Parameters
$date : WC_DateTime

Instance of WC_DateTime.

$format : string = ''

Data format. Defaults to the wc_date_format function if not set.

Tags
since
Return values
string

wc_do_oembeds()

Process oEmbeds.

wc_do_oembeds( $content : string ) : string
Parameters
$content : string

Content.

Tags
since
Return values
string

wc_get_string_before_colon()

Get part of a string before :.

wc_get_string_before_colon( $string : string ) : string

Used for example in shipping methods ids where they take the format method_id:instance_id

Parameters
$string : string

String to extract.

Tags
since
Return values
string

wc_implode_html_attributes()

Implode and escape HTML attributes for output.

wc_implode_html_attributes( $raw_attributes : array ) : string
Parameters
$raw_attributes : array

Attribute name value pairs.

Tags
since
Return values
string

wc_esc_json()

Escape JSON for use on HTML or attribute text nodes.

wc_esc_json( $json : string [, $html : bool = false ] ) : string
Parameters
$json : string

JSON to escape.

$html : bool = false

True if escaping for HTML text node, false for attributes. Determines how quotes are handled.

Tags
since
Return values
string

Escaped JSON.

wc_parse_relative_date_option()

Parse a relative date option from the settings API into a standard format.

wc_parse_relative_date_option( $raw_value : mixed ) : array
Parameters
$raw_value : mixed

Value stored in DB.

Tags
since
Return values
array

Nicely formatted array with number and unit values.

wc_sanitize_endpoint_slug()

Format the endpoint slug, strip out anything not allowed in a url.

wc_sanitize_endpoint_slug( $raw_value : string ) : string
Parameters
$raw_value : string

The raw value.

Tags
since
Return values
string

wc_notice_count()

Get the count of notices added, either for all notices (default) or for one.

wc_notice_count( [ $notice_type : string = '' ] ) : int

particular notice type specified by $notice_type.

Parameters
$notice_type : string = ''

Optional. The name of the notice type - either error, success or notice.

Tags
since
Return values
int

wc_has_notice()

Check if a notice has already been added.

wc_has_notice( $message : string [, $notice_type : string = 'success' ] ) : bool
Parameters
$message : string

The text to display in the notice.

$notice_type : string = 'success'

Optional. The name of the notice type - either error, success or notice.

Tags
since
Return values
bool

wc_add_notice()

Add and store a notice.

wc_add_notice( $message : string [, $notice_type : string = 'success' ] [, $data : array = array() ] ) : mixed
Parameters
$message : string

The text to display in the notice.

$notice_type : string = 'success'

Optional. The name of the notice type - either error, success or notice.

$data : array = array()

Optional notice data.

Tags
since
version
Return values
mixed

wc_set_notices()

Set all notices at once.

wc_set_notices( $notices : array[] ) : mixed
Parameters
$notices : array[]

Array of notices.

Tags
since
Return values
mixed

wc_clear_notices()

Unset all notices.

wc_clear_notices( ) : mixed
Tags
since
Return values
mixed

wc_print_notices()

Prints messages and errors which are stored in the session, then clears them.

wc_print_notices( [ $return : bool = false ] ) : string|null
Parameters
$return : bool = false

true to return rather than echo. @since 3.5.0.

Tags
since
Return values
string|null

wc_print_notice()

Print a single notice immediately.

wc_print_notice( $message : string [, $notice_type : string = 'success' ] [, $data : array = array() ] ) : mixed
Parameters
$message : string

The text to display in the notice.

$notice_type : string = 'success'

Optional. The singular name of the notice type - either error, success or notice.

$data : array = array()

Optional notice data. @since 3.9.0.

Tags
since
version
Return values
mixed

wc_get_notices()

Returns all queued notices, optionally filtered by a notice type.

wc_get_notices( [ $notice_type : string = '' ] ) : array[]
Parameters
$notice_type : string = ''

Optional. The singular name of the notice type - either error, success or notice.

Tags
since
version
Return values
array[]

wc_add_wp_error_notices()

Add notices for WP Errors.

wc_add_wp_error_notices( $errors : WP_Error ) : mixed
Parameters
$errors : WP_Error

Errors.

Return values
mixed

wc_kses_notice()

Filters out the same tags as wp_kses_post, but allows tabindex for <a> element.

wc_kses_notice( $message : string ) : string
Parameters
$message : string

Content to filter through kses.

Tags
since
Return values
string

wc_get_notice_data_attr()

Get notice data attribute.

wc_get_notice_data_attr( $notice : array ) : string
Parameters
$notice : array

Notice data.

Tags
since
Return values
string

wc_get_orders()

Standard way of retrieving orders based on certain parameters.

wc_get_orders( $args : array ) : \WC_Order[]|stdClass

This function should be used for order retrieval so that when we move to custom tables, functions still work.

Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query

Parameters
$args : array

Array of args (above).

Tags
since
Return values
\WC_Order[]|stdClass

Number of pages and an array of order objects if paginate is true, or just an array of values.

wc_get_order_statuses()

Get all order statuses.

wc_get_order_statuses( ) : array
Tags
since
used-by

WC_Order::set_status

Return values
array

wc_is_order_status()

See if a string is an order status.

wc_is_order_status( $maybe_status : string ) : bool
Parameters
$maybe_status : string

Status, including any wc- prefix.

Return values
bool

wc_get_is_paid_statuses()

Get list of statuses which are consider 'paid'.

wc_get_is_paid_statuses( ) : array
Tags
since
Return values
array

wc_get_is_pending_statuses()

Get list of statuses which are consider 'pending payment'.

wc_get_is_pending_statuses( ) : array
Tags
since
Return values
array

wc_get_order_status_name()

Get the nice name for an order status.

wc_get_order_status_name( $status : string ) : string
Parameters
$status : string

Status.

Tags
since
Return values
string

wc_generate_order_key()

Generate an order key with prefix.

wc_generate_order_key( [ $key : string = '' ] ) : string
Parameters
$key : string = ''

Order key without a prefix. By default generates a 13 digit secret.

Tags
since
Return values
string

The order key.

wc_get_order_id_by_order_key()

Finds an Order ID based on an order key.

wc_get_order_id_by_order_key( $order_key : string ) : int
Parameters
$order_key : string

An order key has generated by.

Return values
int

The ID of an order, or 0 if the order could not be found.

wc_get_order_types()

Get all registered order types.

wc_get_order_types( [ $for : string = '' ] ) : array
Parameters
$for : string = ''

Optionally define what you are getting order types for so only relevant types are returned. e.g. for 'order-meta-boxes', 'order-count'.

Tags
since
Return values
array

wc_get_order_type()

Get an order type by post type name.

wc_get_order_type( $type : string ) : bool|array
Parameters
$type : string

Post type name.

Return values
bool|array

Details about the order type.

wc_register_order_type()

Register order type. Do not use before init.

wc_register_order_type( $type : string [, $args : array = array() ] ) : bool

Wrapper for register post type, as well as a method of telling WC which. post types are types of orders, and having them treated as such.

$args are passed to register_post_type, but there are a few specific to this function:

  • exclude_from_orders_screen (bool) Whether or not this order type also get shown in the main. orders screen.
  • add_order_meta_boxes (bool) Whether or not the order type gets shop_order meta boxes.
  • exclude_from_order_count (bool) Whether or not this order type is excluded from counts.
  • exclude_from_order_views (bool) Whether or not this order type is visible by customers when. viewing orders e.g. on the my account page.
  • exclude_from_order_reports (bool) Whether or not to exclude this type from core reports.
  • exclude_from_order_sales_reports (bool) Whether or not to exclude this type from core sales reports.
Parameters
$type : string

Post type. (max. 20 characters, can not contain capital letters or spaces).

$args : array = array()

An array of arguments.

Tags
since
see

for $args used in that function

Return values
bool

Success or failure

wc_processing_order_count()

Return the count of processing orders.

wc_processing_order_count( ) : int
Return values
int

wc_orders_count()

Return the orders count of a specific order status.

wc_orders_count( $status : string ) : int
Parameters
$status : string

Status.

Return values
int

wc_downloadable_file_permission()

Grant downloadable product access to the file identified by $download_id.

wc_downloadable_file_permission( $download_id : string , $product : int|WC_Product , $order : WC_Order [, $qty : int = 1 ] ) : int|bool
Parameters
$download_id : string

File identifier.

$product : int|WC_Product

Product instance or ID.

$order : WC_Order

Order data.

$qty : int = 1

Quantity purchased.

Return values
int|bool

insert id or false on failure.

wc_downloadable_product_permissions()

Order Status completed - give downloadable product access to customer.

wc_downloadable_product_permissions( $order_id : int [, $force : bool = false ] ) : mixed
Parameters
$order_id : int

Order ID.

$force : bool = false

Force downloadable permissions.

Return values
mixed

wc_delete_shop_order_transients()

Clear all transients cache for order data.

wc_delete_shop_order_transients( $order : int|WC_Order ) : mixed
Parameters
$order : int|WC_Order

Order instance or ID.

Return values
mixed

wc_ship_to_billing_address_only()

See if we only ship to billing addresses.

wc_ship_to_billing_address_only( ) : bool
Return values
bool

wc_create_refund()

Create a new order refund programmatically.

wc_create_refund( [ $args : array = array() ] ) : WC_Order_Refund|WP_Error

Returns a new refund object on success which can then be used to add additional data.

Parameters
$args : array = array()

New refund arguments.

Tags
since
throws

Throws exceptions when fail to create, but returns WP_Error instead.

Return values
WC_Order_Refund|WP_Error

wc_refund_payment()

Try to refund the payment for an order via the gateway.

wc_refund_payment( $order : WC_Order , $amount : string [, $reason : string = '' ] ) : bool|WP_Error
Parameters
$order : WC_Order

Order instance.

$amount : string

Amount to refund.

$reason : string = ''

Refund reason.

Tags
since
throws

Throws exceptions when fail to refund, but returns WP_Error instead.

Return values
bool|WP_Error

wc_restock_refunded_items()

Restock items during refund.

wc_restock_refunded_items( $order : WC_Order , $refunded_line_items : array ) : mixed
Parameters
$order : WC_Order

Order instance.

$refunded_line_items : array

Refunded items list.

Tags
since
Return values
mixed

wc_get_tax_class_by_tax_id()

Get tax class by tax id.

wc_get_tax_class_by_tax_id( $tax_id : int ) : string
Parameters
$tax_id : int

Tax ID.

Tags
since
Return values
string

wc_order_fully_refunded()

When refunding an order, create a refund line item if the partial refunds do not match order total.

wc_order_fully_refunded( $order_id : int ) : mixed

This is manual; no gateway refund will be performed.

Parameters
$order_id : int

Order ID.

Tags
since
Return values
mixed

wc_order_search()

Search orders.

wc_order_search( $term : string ) : array
Parameters
$term : string

Term to search.

Tags
since
Return values
array

List of orders ID.

wc_update_total_sales_counts()

Update total sales amount for each product within a paid order.

wc_update_total_sales_counts( $order_id : int ) : mixed
Parameters
$order_id : int

Order ID.

Tags
since
Return values
mixed

wc_update_coupon_usage_counts()

Update used coupon amount for each coupon within an order.

wc_update_coupon_usage_counts( $order_id : int ) : mixed
Parameters
$order_id : int

Order ID.

Tags
since
Return values
mixed

wc_cancel_unpaid_orders()

Cancel all unpaid orders after held duration to prevent stock lock for those products.

wc_cancel_unpaid_orders( ) : mixed
Return values
mixed

wc_sanitize_order_id()

Sanitize order id removing unwanted characters.

wc_sanitize_order_id( $order_id : int ) : mixed

E.g Users can sometimes try to track an order id using # with no success. This function will fix this.

Parameters
$order_id : int

Order ID.

Tags
since
Return values
mixed

wc_get_order_note()

Get an order note.

wc_get_order_note( $data : int|WP_Comment ) : stdClass|null
Parameters
$data : int|WP_Comment

Note ID (or WP_Comment instance for internal use only).

Tags
since
Return values
stdClass|null

Object with order note details or null when does not exists.

wc_get_order_notes()

Get order notes.

wc_get_order_notes( $args : array ) : \stdClass[]
Parameters
$args : array

Query arguments { Array of query parameters.

@type string $limit         Maximum number of notes to retrieve.
                            Default empty (no limit).
@type int    $order_id      Limit results to those affiliated with a given order ID.
                            Default 0.
@type array  $order__in     Array of order IDs to include affiliated notes for.
                            Default empty.
@type array  $order__not_in Array of order IDs to exclude affiliated notes for.
                            Default empty.
@type string $orderby       Define how should sort notes.
                            Accepts 'date_created', 'date_created_gmt' or 'id'.
                            Default: 'id'.
@type string $order         How to order retrieved notes.
                            Accepts 'ASC' or 'DESC'.
                            Default: 'DESC'.
@type string $type          Define what type of note should retrieve.
                            Accepts 'customer', 'internal' or empty for both.
                            Default empty.

}

Tags
since
Return values
\stdClass[]

Array of stdClass objects with order notes details.

wc_create_order_note()

Create an order note.

wc_create_order_note( $order_id : int , $note : string [, $is_customer_note : bool = false ] [, $added_by_user : bool = false ] ) : int|WP_Error
Parameters
$order_id : int

Order ID.

$note : string

Note to add.

$is_customer_note : bool = false

If is a costumer note.

$added_by_user : bool = false

If note is create by an user.

Tags
since
Return values
int|WP_Error

Integer when created or WP_Error when found an error.

wc_delete_order_note()

Delete an order note.

wc_delete_order_note( $note_id : int ) : bool
Parameters
$note_id : int

Order note.

Tags
since
Return values
bool

True on success, false on failure.

wc_add_order_item()

Add a item to an order (for example a line item).

wc_add_order_item( $order_id : int , $item_array : array ) : int|bool
Parameters
$order_id : int

Order ID.

$item_array : array

Items list.

Tags
throws

When WC_Data_Store::load validation fails.

Return values
int|bool

Item ID or false

wc_update_order_item()

Update an item for an order.

wc_update_order_item( $item_id : int , $args : array ) : bool
Parameters
$item_id : int

Item ID.

$args : array

Either order_item_type or order_item_name.

Tags
since
throws

When WC_Data_Store::load validation fails.

Return values
bool

True if successfully updated, false otherwise.

wc_delete_order_item()

Delete an item from the order it belongs to based on item id.

wc_delete_order_item( $item_id : int ) : bool
Parameters
$item_id : int

Item ID.

Tags
throws

When WC_Data_Store::load validation fails.

Return values
bool

wc_update_order_item_meta()

WooCommerce Order Item Meta API - Update term meta.

wc_update_order_item_meta( $item_id : int , $meta_key : string , $meta_value : string [, $prev_value : string = '' ] ) : bool
Parameters
$item_id : int

Item ID.

$meta_key : string

Meta key.

$meta_value : string

Meta value.

$prev_value : string = ''

Previous value (default: '').

Tags
throws

When WC_Data_Store::load validation fails.

Return values
bool

wc_add_order_item_meta()

WooCommerce Order Item Meta API - Add term meta.

wc_add_order_item_meta( $item_id : int , $meta_key : string , $meta_value : string [, $unique : bool = false ] ) : int
Parameters
$item_id : int

Item ID.

$meta_key : string

Meta key.

$meta_value : string

Meta value.

$unique : bool = false

If meta data should be unique (default: false).

Tags
throws

When WC_Data_Store::load validation fails.

Return values
int

New row ID or 0.

wc_delete_order_item_meta()

WooCommerce Order Item Meta API - Delete term meta.

wc_delete_order_item_meta( $item_id : int , $meta_key : string [, $meta_value : string = '' ] [, $delete_all : bool = false ] ) : bool
Parameters
$item_id : int

Item ID.

$meta_key : string

Meta key.

$meta_value : string = ''

Meta value (default: '').

$delete_all : bool = false

Delete all meta data, defaults to false.

Tags
throws

When WC_Data_Store::load validation fails.

Return values
bool

wc_get_order_item_meta()

WooCommerce Order Item Meta API - Get term meta.

wc_get_order_item_meta( $item_id : int , $key : string [, $single : bool = true ] ) : mixed
Parameters
$item_id : int

Item ID.

$key : string

Meta key.

$single : bool = true

Whether to return a single value. (default: true).

Tags
throws

When WC_Data_Store::load validation fails.

Return values
mixed

wc_get_order_id_by_order_item_id()

Get order ID by order item ID.

wc_get_order_id_by_order_item_id( $item_id : int ) : int
Parameters
$item_id : int

Item ID.

Tags
throws

When WC_Data_Store::load validation fails.

Return values
int

wc_get_products()

Standard way of retrieving products based on certain parameters.

wc_get_products( $args : array ) : array|stdClass

This function should be used for product retrieval so that we have a data agnostic way to get a list of products.

Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query

Parameters
$args : array

Array of args (above).

Tags
since
Return values
array|stdClass

Number of pages and an array of product objects if paginate is true, or just an array of values.

wc_get_product()

Main function for returning products, uses the WC_Product_Factory class.

wc_get_product( [ $the_product : mixed = false ] [, $deprecated : array = array() ] ) : WC_Product|null|false

This function should only be called after 'init' action is finished, as there might be taxonomies that are getting registered during the init action.

Parameters
$the_product : mixed = false

Post object or post ID of the product.

$deprecated : array = array()

Previously used to pass arguments to the factory, e.g. to force a type.

Tags
since
Return values
WC_Product|null|false

wc_get_product_object()

Get a product object.

wc_get_product_object( $product_type : string , $product_id : int ) : WC_Product
Parameters
$product_type : string

Product type. If used an invalid type a WC_Product_Simple instance will be returned.

$product_id : int

Product ID.

Tags
see
since
Return values
WC_Product

wc_product_sku_enabled()

Returns whether or not SKUS are enabled.

wc_product_sku_enabled( ) : bool
Return values
bool

wc_product_weight_enabled()

Returns whether or not product weights are enabled.

wc_product_weight_enabled( ) : bool
Return values
bool

wc_product_dimensions_enabled()

Returns whether or not product dimensions (HxWxD) are enabled.

wc_product_dimensions_enabled( ) : bool
Return values
bool

wc_delete_product_transients()

Clear transient cache for product data.

wc_delete_product_transients( $post_id : int ) : mixed
Parameters
$post_id : int

(default: 0) The product ID.

Return values
mixed

wc_get_product_ids_on_sale()

Function that returns an array containing the IDs of the products that are on sale.

wc_get_product_ids_on_sale( ) : array
Tags
since
Return values
array

wc_get_featured_product_ids()

Function that returns an array containing the IDs of the featured products.

wc_get_featured_product_ids( ) : array
Tags
since
Return values
array

wc_product_post_type_link()

Filter to allow product_cat in the permalinks for products.

wc_product_post_type_link( $permalink : string , $post : WP_Post ) : string
Parameters
$permalink : string

The existing permalink URL.

$post : WP_Post

WP_Post object.

Return values
string

wc_placeholder_img_src()

Get the placeholder image URL either from media, or use the fallback image.

wc_placeholder_img_src( [ $size : string = 'woocommerce_thumbnail' ] ) : string
Parameters
$size : string = 'woocommerce_thumbnail'

Thumbnail size to use.

Return values
string

wc_placeholder_img()

Get the placeholder image.

wc_placeholder_img( [ $size : string = 'woocommerce_thumbnail' ] [, $attr : string|array = '' ] ) : string

Uses wp_get_attachment_image if using an attachment ID @since 3.6.0 to handle responsiveness.

Parameters
$size : string = 'woocommerce_thumbnail'

Image size.

$attr : string|array = ''

Optional. Attributes for the image markup. Default empty.

Return values
string

wc_get_formatted_variation()

Variation Formatting.

wc_get_formatted_variation( $variation : array|WC_Product_Variation [, $flat : bool = false ] [, $include_names : bool = true ] [, $skip_attributes_in_name : bool = false ] ) : string

Gets a formatted version of variation data or item meta.

Parameters
$variation : array|WC_Product_Variation

Variation object.

$flat : bool = false

Should this be a flat list or HTML list? (default: false).

$include_names : bool = true

include attribute names/labels in the list.

$skip_attributes_in_name : bool = false

Do not list attributes already part of the variation name.

Return values
string

wc_scheduled_sales()

Function which handles the start and end of scheduled sales via cron.

wc_scheduled_sales( ) : mixed
Return values
mixed

wc_get_attachment_image_attributes()

Get attachment image attributes.

wc_get_attachment_image_attributes( $attr : array ) : array
Parameters
$attr : array

Image attributes.

Return values
array

wc_prepare_attachment_for_js()

Prepare attachment for JavaScript.

wc_prepare_attachment_for_js( $response : array ) : array
Parameters
$response : array

JS version of a attachment post object.

Return values
array

wc_track_product_view()

Track product views.

wc_track_product_view( ) : mixed
Return values
mixed

wc_get_product_types()

Get product types.

wc_get_product_types( ) : array
Tags
since
Return values
array

wc_product_has_unique_sku()

Check if product sku is unique.

wc_product_has_unique_sku( $product_id : int , $sku : string ) : bool
Parameters
$product_id : int

Product ID.

$sku : string

Product SKU.

Tags
since
Return values
bool

wc_product_force_unique_sku()

Force a unique SKU.

wc_product_force_unique_sku( $product_id : int ) : mixed
Parameters
$product_id : int

Product ID.

Tags
since
Return values
mixed

wc_product_generate_unique_sku()

Recursively appends a suffix until a unique SKU is found.

wc_product_generate_unique_sku( $product_id : int , $sku : string , $index : int ) : string
Parameters
$product_id : int

Product ID.

$sku : string

Product SKU.

$index : int

An optional index that can be added to the product SKU.

Tags
since
Return values
string

wc_get_product_id_by_sku()

Get product ID by SKU.

wc_get_product_id_by_sku( $sku : string ) : int
Parameters
$sku : string

Product SKU.

Tags
since
Return values
int

wc_get_product_variation_attributes()

Get attibutes/data for an individual variation from the database and maintain it's integrity.

wc_get_product_variation_attributes( $variation_id : int ) : array
Parameters
$variation_id : int

Variation ID.

Tags
since
Return values
array

wc_get_product_cat_ids()

Get all product cats for a product by ID, including hierarchy

wc_get_product_cat_ids( $product_id : int ) : array
Parameters
$product_id : int

Product ID.

Tags
since
Return values
array

wc_get_product_attachment_props()

Gets data about an attachment, such as alt text and captions.

wc_get_product_attachment_props( [ $attachment_id : int|null = null ] [, $product : WC_Product|bool = false ] ) : array
Parameters
$attachment_id : int|null = null

Attachment ID.

$product : WC_Product|bool = false

WC_Product object.

Tags
since
Return values
array

wc_get_product_visibility_options()

Get product visibility options.

wc_get_product_visibility_options( ) : array
Tags
since
Return values
array

wc_get_product_tax_class_options()

Get product tax class options.

wc_get_product_tax_class_options( ) : array
Tags
since
Return values
array

wc_get_product_stock_status_options()

Get stock status options.

wc_get_product_stock_status_options( ) : array
Tags
since
Return values
array

wc_get_product_backorder_options()

Get backorder options.

wc_get_product_backorder_options( ) : array
Tags
since
Return values
array

wc_get_related_products()

Get related products based on product category and tags.

wc_get_related_products( $product_id : int [, $limit : int = 5 ] [, $exclude_ids : array = array() ] ) : array
Parameters
$product_id : int

Product ID.

$limit : int = 5

Limit of results.

$exclude_ids : array = array()

Exclude IDs from the results.

Tags
since
Return values
array

wc_get_product_term_ids()

Retrieves product term ids for a taxonomy.

wc_get_product_term_ids( $product_id : int , $taxonomy : string ) : array
Parameters
$product_id : int

Product ID.

$taxonomy : string

Taxonomy slug.

Tags
since
Return values
array

wc_get_price_including_tax()

For a given product, and optionally price/qty, work out the price with tax included, based on store settings.

wc_get_price_including_tax( $product : WC_Product [, $args : array = array() ] ) : float
Parameters
$product : WC_Product

WC_Product object.

$args : array = array()

Optional arguments to pass product quantity and price.

Tags
since
Return values
float

wc_get_price_excluding_tax()

For a given product, and optionally price/qty, work out the price with tax excluded, based on store settings.

wc_get_price_excluding_tax( $product : WC_Product [, $args : array = array() ] ) : float
Parameters
$product : WC_Product

WC_Product object.

$args : array = array()

Optional arguments to pass product quantity and price.

Tags
since
Return values
float

wc_get_price_to_display()

Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.

wc_get_price_to_display( $product : WC_Product [, $args : array = array() ] ) : float
Parameters
$product : WC_Product

WC_Product object.

$args : array = array()

Optional arguments to pass product quantity and price.

Tags
since
Return values
float

wc_get_product_category_list()

Returns the product categories in a list.

wc_get_product_category_list( $product_id : int [, $sep : string = ', ' ] [, $before : string = '' ] [, $after : string = '' ] ) : string
Parameters
$product_id : int

Product ID.

$sep : string = ', '

(default: ', ').

$before : string = ''

(default: '').

$after : string = ''

(default: '').

Return values
string

wc_get_product_tag_list()

Returns the product tags in a list.

wc_get_product_tag_list( $product_id : int [, $sep : string = ', ' ] [, $before : string = '' ] [, $after : string = '' ] ) : string
Parameters
$product_id : int

Product ID.

$sep : string = ', '

(default: ', ').

$before : string = ''

(default: '').

$after : string = ''

(default: '').

Return values
string

wc_products_array_filter_visible()

Callback for array filter to get visible only.

wc_products_array_filter_visible( $product : WC_Product ) : bool
Parameters
$product : WC_Product

WC_Product object.

Tags
since
Return values
bool

wc_products_array_filter_visible_grouped()

Callback for array filter to get visible grouped products only.

wc_products_array_filter_visible_grouped( $product : WC_Product ) : bool
Parameters
$product : WC_Product

WC_Product object.

Tags
since
Return values
bool

wc_products_array_filter_editable()

Callback for array filter to get products the user can edit only.

wc_products_array_filter_editable( $product : WC_Product ) : bool
Parameters
$product : WC_Product

WC_Product object.

Tags
since
Return values
bool

wc_products_array_filter_readable()

Callback for array filter to get products the user can view only.

wc_products_array_filter_readable( $product : WC_Product ) : bool
Parameters
$product : WC_Product

WC_Product object.

Tags
since
Return values
bool

wc_products_array_orderby()

Sort an array of products by a value.

wc_products_array_orderby( $products : array [, $orderby : string = 'date' ] [, $order : string = 'desc' ] ) : array
Parameters
$products : array

List of products to be ordered.

$orderby : string = 'date'

Optional order criteria.

$order : string = 'desc'

Ascending or descending order.

Tags
since
Return values
array

wc_deferred_product_sync()

Queue a product for syncing at the end of the request.

wc_deferred_product_sync( $product_id : int ) : mixed
Parameters
$product_id : int

Product ID.

Return values
mixed

wc_update_product_lookup_tables_is_running()

See if the lookup table is being generated already.

wc_update_product_lookup_tables_is_running( ) : bool
Tags
since
Return values
bool

wc_update_product_lookup_tables()

Populate lookup table data for products.

wc_update_product_lookup_tables( ) : mixed
Tags
since
Return values
mixed

wc_update_product_lookup_tables_column()

Populate lookup table column data.

wc_update_product_lookup_tables_column( $column : string ) : mixed
Parameters
$column : string

Column name to set.

Tags
since
Return values
mixed

wc_update_product_lookup_tables_rating_count()

Populate rating count lookup table data for products.

wc_update_product_lookup_tables_rating_count( $rows : array ) : mixed
Parameters
$rows : array

Rows of rating counts to update in lookup table.

Tags
since
Return values
mixed

wc_update_product_lookup_tables_rating_count_batch()

Populate a batch of rating count lookup table data for products.

wc_update_product_lookup_tables_rating_count_batch( $offset : array , $limit : array ) : mixed
Parameters
$offset : array

Offset to query.

$limit : array

Limit to query.

Tags
since
Return values
mixed

wc_rest_allowed_image_mime_types()

Returns image mime types users are allowed to upload via the API.

wc_rest_allowed_image_mime_types( ) : array
Tags
since
Return values
array

wc_rest_upload_image_from_url()

Upload image from URL.

wc_rest_upload_image_from_url( $image_url : string ) : array|WP_Error
Parameters
$image_url : string

Image URL.

Tags
since
Return values
array|WP_Error

Attachment data or error message.

wc_rest_set_uploaded_image_as_attachment()

Set uploaded image as attachment.

wc_rest_set_uploaded_image_as_attachment( $upload : array , $id : int ) : int
Parameters
$upload : array

Upload information from wp_upload_bits.

$id : int

Post ID. Default to 0.

Tags
since
Return values
int

Attachment ID

wc_rest_validate_reports_request_arg()

Validate reports request arguments.

wc_rest_validate_reports_request_arg( $value : mixed , $request : WP_REST_Request , $param : string ) : WP_Error|bool
Parameters
$value : mixed

Value to valdate.

$request : WP_REST_Request

Request instance.

$param : string

Param to validate.

Tags
since
Return values
WP_Error|bool

wc_rest_urlencode_rfc3986()

Encodes a value according to RFC 3986.

wc_rest_urlencode_rfc3986( $value : string|array ) : string|array

Supports multidimensional arrays.

Parameters
$value : string|array

The value to encode.

Tags
since
Return values
string|array

Encoded values.

wc_rest_check_post_permissions()

Check permissions of posts on REST API.

wc_rest_check_post_permissions( $post_type : string [, $context : string = 'read' ] , $object_id : int ) : bool
Parameters
$post_type : string

Post type.

$context : string = 'read'

Request context.

$object_id : int

Post ID.

Tags
since
Return values
bool

wc_rest_check_user_permissions()

Check permissions of users on REST API.

wc_rest_check_user_permissions( [ $context : string = 'read' ] , $object_id : int ) : bool
Parameters
$context : string = 'read'

Request context.

$object_id : int

Post ID.

Tags
since
Return values
bool

wc_rest_check_product_term_permissions()

Check permissions of product terms on REST API.

wc_rest_check_product_term_permissions( $taxonomy : string [, $context : string = 'read' ] , $object_id : int ) : bool
Parameters
$taxonomy : string

Taxonomy.

$context : string = 'read'

Request context.

$object_id : int

Post ID.

Tags
since
Return values
bool

wc_rest_check_manager_permissions()

Check manager permissions on REST API.

wc_rest_check_manager_permissions( $object : string [, $context : string = 'read' ] ) : bool
Parameters
$object : string

Object.

$context : string = 'read'

Request context.

Tags
since
Return values
bool

wc_rest_check_product_reviews_permissions()

Check product reviews permissions on REST API.

wc_rest_check_product_reviews_permissions( [ $context : string = 'read' ] , $object_id : string ) : bool
Parameters
$context : string = 'read'

Request context.

$object_id : string

Object ID.

Tags
since
Return values
bool

wc_update_product_stock()

Update a product's stock amount.

wc_update_product_stock( $product : int|WC_Product [, $stock_quantity : int|null = null ] [, $operation : string = 'set' ] [, $updating : bool = false ] ) : bool|int|null

Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues).

Parameters
$product : int|WC_Product

Product ID or product instance.

$stock_quantity : int|null = null

Stock quantity.

$operation : string = 'set'

Type of opertion, allows 'set', 'increase' and 'decrease'.

$updating : bool = false

If true, the product object won't be saved here as it will be updated later.

Tags
since

this supports set, increase and decrease.

Return values
bool|int|null

wc_update_product_stock_status()

Update a product's stock status.

wc_update_product_stock_status( $product_id : int , $status : string ) : mixed
Parameters
$product_id : int

Product ID.

$status : string

Status.

Return values
mixed

wc_maybe_reduce_stock_levels()

When a payment is complete, we can reduce stock levels for items within an order.

wc_maybe_reduce_stock_levels( $order_id : int ) : mixed
Parameters
$order_id : int

Order ID.

Tags
since
Return values
mixed

wc_maybe_increase_stock_levels()

When a payment is cancelled, restore stock.

wc_maybe_increase_stock_levels( $order_id : int ) : mixed
Parameters
$order_id : int

Order ID.

Tags
since
Return values
mixed

wc_reduce_stock_levels()

Reduce stock levels for items within an order, if stock has not already been reduced for the items.

wc_reduce_stock_levels( $order_id : int|WC_Order ) : mixed
Parameters
$order_id : int|WC_Order

Order ID or order instance.

Tags
since
Return values
mixed

wc_trigger_stock_change_notifications()

After stock change events, triggers emails and adds order notes.

wc_trigger_stock_change_notifications( $order : WC_Order , $changes : array ) : mixed
Parameters
$order : WC_Order

order object.

$changes : array

Array of changes.

Tags
since
Return values
mixed

wc_increase_stock_levels()

Increase stock levels for items within an order.

wc_increase_stock_levels( $order_id : int|WC_Order ) : mixed
Parameters