add new | Links(wooBookings etc.) | conditions/checks | Order meta

WooCommerce taxonomies and post types

WooCommerce installs the following post types and taxonomies — the first levels are post types; and the second levels are taxonomies for their top-level post type.

query using wp_query (wc_query)!



$params = array(
        'posts_per_page' => 5, 
        'post_type' => 'product'
); 
$wc_query = new WP_Query($params); 

 if ($wc_query->have_posts()) : 
 while ($wc_query->have_posts()) : 
           $wc_query->the_post();  
 the_title(); 
 endwhile; 
 wp_reset_postdata();  
 else: 
     _e( 'No Products' )
     endif;

Template Hooks

Actions

HOOK FILE(S)
get_product_search_form woocommerce-template.php
woocommerce_.$product->product_type._add_to_cart woocommerce-template.php
woocommerce_after_main_content archive-product.php, single-product.php
woocommerce_after_shop_loop archive-product.php, loop-shop.php, woocommerce-template.php
woocommerce_after_shop_loop_item content-product.php
woocommerce_after_shop_loop_item_title content-product.php
woocommerce_after_single_product content-single-product.php
woocommerce_after_single_product_summary content-single-product.php
woocommerce_after_subcategory content-product_cat.php
woocommerce_after_subcategory_title content-product_cat.php
woocommerce_archive_description archive-product.php, woocommerce-template.php
woocommerce_before_main_content archive-product.php, single-product.php
woocommerce_before_shop_loop archive-product.php, loop-shop.php, woocommerce-template.php
woocommerce_before_shop_loop_item content-product.php
woocommerce_before_shop_loop_item_title content-product.php
woocommerce_before_single_product content-single-product.php
woocommerce_before_single_product_summary content-single-product.php
woocommerce_before_subcategory content-product_cat.php
woocommerce_before_subcategory_title content-product_cat.php
woocommerce_product_thumbnails product-image.php
woocommerce_sidebar archive-product.php, single-product.php
woocommerce_single_product_summary content-single-product.php

Filters

HOOK FILE(S)
default_checkout_country woocommerce-template.php, woocommerce-template.php, woocommerce-template.php
get_product_search_form woocommerce-template.php, woocommerce-template.php
loop_shop_columns content-product.php, content-product_cat.php
single_product_small_thumbnail_size product-thumbnails.php, woocommerce-template.php
the_content order-details.php, email-order-items.php, woocommerce-template.php
the_title woocommerce-template.php
woocommerce_attribute product-attributes.php, product-attributes.php
woocommerce_default_catalog_orderby woocommerce-template.php
woocommerce_demo_store woocommerce-template.php
woocommerce_form_field_.$args[type] woocommerce-template.php
woocommerce_page_title woocommerce-template.php
woocommerce_product_review_comment_form_args single-product-reviews.php
woocommerce_product_subcategories_args woocommerce-template.php
woocommerce_product_thumbnails_columns product-thumbnails.php
woocommerce_quantity_input_args woocommerce-template.php
woocommerce_subcategory_count_html content-product_cat.php

Widget Hooks

 

Filters

HOOK FILE(S)
widget_title class-wc-widget-best-sellers.php, class-wc-widget-cart.php, class-wc-widget-featured-products.php, class-wc-widget-layered-nav-filters.php, class-wc-widget-layered-nav.php, class-wc-widget-login.php, class-wc-widget-login.php, class-wc-widget-onsale.php, class-wc-widget-price-filter.php, class-wc-widget-product-categories.php, class-wc-widget-product-search.php, class-wc-widget-product-tag-cloud.php, class-wc-widget-random-products.php, class-wc-widget-recent-products.php, class-wc-widget-recent-reviews.php, class-wc-widget-recently-viewed.php, class-wc-widget-top-rated-products.php
woocommerce_product_categories_widget_args class-wc-widget-product-categories.php
woocommerce_product_tag_cloud_widget_args class-wc-widget-product-tag-cloud.php

Class Hooks

 

Actions

HOOK FILE(S)
woocommerce_product_set_stock_status abstract-wc-product.php

Filters

HOOK FILE(S)
list_product_cats class-product-cat-dropdown-walker.php
single_product_large_thumbnail_size class-wc-product-variable.php
widget_title class-wc-widget-best-sellers.php, class-wc-widget-cart.php, class-wc-widget-featured-products.php, class-wc-widget-layered-nav-filters.php, class-wc-widget-layered-nav.php, class-wc-widget-login.php, class-wc-widget-login.php, class-wc-widget-onsale.php, class-wc-widget-price-filter.php, class-wc-widget-product-categories.php, class-wc-widget-product-search.php, class-wc-widget-product-tag-cloud.php, class-wc-widget-random-products.php, class-wc-widget-recent-products.php, class-wc-widget-recent-reviews.php, class-wc-widget-recently-viewed.php, class-wc-widget-top-rated-products.php
woocommerce_add_to_cart_url abstract-wc-product.php
woocommerce_empty_price_html abstract-wc-product.php
woocommerce_file_download_path class-wc-product-variation.php, abstract-wc-product.php
woocommerce_file_download_paths class-wc-product-variation.php, abstract-wc-product.php
woocommerce_free_price_html abstract-wc-product.php
woocommerce_free_sale_price_html abstract-wc-product.php
woocommerce_get_availability abstract-wc-product.php
woocommerce_get_price abstract-wc-product.php
woocommerce_get_price_excluding_tax abstract-wc-product.php
woocommerce_get_price_html class-wc-product-grouped.php, class-wc-product-variable.php, abstract-wc-product.php
woocommerce_get_price_including_tax abstract-wc-product.php
woocommerce_grouped_price_html class-wc-product-grouped.php
woocommerce_is_purchasable class-wc-product-external.php, class-wc-product-grouped.php, abstract-wc-product.php
woocommerce_is_sold_individually abstract-wc-product.php
woocommerce_price_html abstract-wc-product.php
woocommerce_product_categories_widget_args class-wc-widget-product-categories.php
woocommerce_product_class class-wc-product-factory.php
woocommerce_product_default_attributes class-wc-product-variable.php
woocommerce_product_is_visible class-wc-product-variation.php, abstract-wc-product.php
woocommerce_product_parent abstract-wc-product.php
woocommerce_product_tag_cloud_widget_args class-wc-widget-product-tag-cloud.php
woocommerce_product_tax_class abstract-wc-product.php
woocommerce_product_title class-wc-product-simple.php, abstract-wc-product.php
woocommerce_sale_price_html abstract-wc-product.php
woocommerce_stock_amount class-wc-checkout.php, class-wc-product-grouped.php, class-wc-product-variable.php, class-wc-product-variable.php, class-wc-product-variable.php, class-wc-product-variable.php, class-wc-product-variation.php, class-wc-product-variation.php, class-wc-product-variation.php, abstract-wc-product.php
woocommerce_stock_html class-wc-product-variable.php
woocommerce_variable_empty_price_html class-wc-product-variable.php
woocommerce_variable_free_price_html class-wc-product-variable.php
woocommerce_variable_free_sale_price_html class-wc-product-variable.php
woocommerce_variable_price_html class-wc-product-variable.php
woocommerce_variable_sale_price_html class-wc-product-variable.php
woocommerce_variation_empty_price_html class-wc-product-variation.php
woocommerce_variation_free_price_html class-wc-product-variation.php
woocommerce_variation_price_html class-wc-product-variation.php
woocommerce_variation_sale_price_html class-wc-product-variation.php

woodocs

Admin Hooks

 

Actions

HOOK FILE(S)
media_upload_file woocommerce-admin-functions.php
woocommerce_admin_attribute_types woocommerce-admin-attributes.php, woocommerce-admin-attributes.php
woocommerce_admin_css woocommerce-admin-init.php
woocommerce_admin_field_.$value[type] woocommerce-admin-settings.php
woocommerce_duplicate_product duplicate_product.php
woocommerce_reports_tabs woocommerce-admin-reports.php
woocommerce_right_now_orders_table_end woocommerce-admin-dashboard.php
woocommerce_right_now_shop_content_table_end woocommerce-admin-dashboard.php
woocommerce_settings_.sanitize_title$value[id] woocommerce-admin-settings.php
woocommerce_settings_.sanitize_title$value[id]._after woocommerce-admin-settings.php
woocommerce_settings_.sanitize_title$value[id]._end woocommerce-admin-settings.php
woocommerce_settings_saved woocommerce-admin-settings.php
woocommerce_settings_start woocommerce-admin-settings.php
woocommerce_settings_tabs woocommerce-admin-settings.php
woocommerce_settings_tabs_.$current_tab woocommerce-admin-settings.php
woocommerce_update_options woocommerce-admin-settings.php
woocommerce_update_options_.$current_tab woocommerce-admin-settings.php
woocommerce_update_options_.$current_tab._.$current_section woocommerce-admin-settings.php, woocommerce-admin-settings.php
woocommerce_update_options_.$current_tab._.$current_section_class->id woocommerce-admin-settings.php, woocommerce-admin-settings.php

Filters

Conditions and class active checks

// Check if plugin active
class_exists( 'WooCommerce' );

// Get The Page ID You Need
get_option( 'woocommerce_shop_page_id' ); 
get_option( 'woocommerce_cart_page_id' ); 
get_option( 'woocommerce_checkout_page_id' );
get_option( 'woocommerce_pay_page_id' ); 
get_option( 'woocommerce_thanks_page_id' ); 
get_option( 'woocommerce_myaccount_page_id' ); 
get_option( 'woocommerce_edit_address_page_id' ); 
get_option( 'woocommerce_view_order_page_id' ); 
get_option( 'woocommerce_terms_page_id' ); 

// Conditional tags
// http://docs.woothemes.com/document/conditional-tags/
is_woocommerce();
is_shop();
is_product_category();
is_product_tag();
is_product();
is_cart();
is_checkout();
is_account_page();

// Get Product ID
 
$product->get_id(); (fixes the error: "Notice: id was called incorrectly. Product properties should not be accessed directly")
 
// Get Product General Info
 
$product->get_type();
$product->get_name();
$product->get_slug();
get_permalink( $product->get_id() );
// source: https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html


Order meta

// Get Order ID
$order->get_id()
 
// Get Order Totals $0.00
$order->get_formatted_order_total( )
$order->get_cart_tax()
// Get Order Payment Details
$order->get_payment_method( string $context = 'view'  )
$order->get_payment_method_title( string $context = 'view'  )
$order->get_transaction_id( string $context = 'view'  )
 
// Get Order URLs
$order->get_checkout_payment_url( boolean $on_checkout = false  )
$order->get_checkout_order_received_url( )
$order->get_cancel_order_url( string $redirect = ''  )
$order->get_cancel_order_url_raw( string $redirect = ''  )
$order->get_cancel_endpoint( )
$order->get_view_order_url( )
$order->get_edit_order_url( )
 
// Get Order Status
$order->get_status( )
 
// source: https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html
// Get $order object from order ID
 
$order = wc_get_order( $order_id );
 
// Now you have access to (see above)...
 
$order->get_id()
$order->get_formatted_order_total( )
// etc.
// etc.

Cart Items

https://www.sitepoint.com/woocommerce-actions-and-filters-manipulate-cart/
get_cart_contents() 
get_cart_contents_total() //after discounts
get_removed_cart_contents() 
get_totals()
get_total( $context = 'view' ) //cart total after calculation
get_totals_var( $key ) //Get a total. $key Key of element in $totals array.
get_subtotal()

get_cart_total() //Gets the cart contents total (after calculation).
get_cart_subtotal( $compound = false ) {
_filters( 'woocommerce_cart_subtotal', $cart_subtotal, $compound, $this )}


get_cart() //Returns the contents of the cart in an array.
get_cart_item( $item_key ) //Returns a specific item in the cart.
is_empty() //Checks if the cart is empty. Bool
_action( 'woocommerce_before_calculate_totals', $this );
_action( 'woocommerce_after_calculate_totals', $this );
_action( 'woocommerce_cart_calculate_fees', $this ); //Trigger an action so 3rd parties can add custom fees.

// Get the product row subtotal. 

get_product_subtotal( $product, $quantity ) { 
_filters( 'woocommerce_cart_product_subtotal', $product_subtotal, $product, $quantity, $this );} 

//Reset cart totals to the defaults. Useful before running calculations.
reset_totals() {
_action( 'woocommerce_cart_reset', $this, false );}
------------------

uses `add_fee()`

 'name'      => $name,
            'amount'    => (float) $amount,
            'taxable'   => $taxable,
            'tax_class' => $tax_class,
------------------

Add item after merging with $cart_item_data - hook to allow plugins to modify cart item.

apply_filters( 'woocommerce_add_cart_item', https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#83-88
_action( 'woocommerce_add_to_cart', function($cart_item_key)
'key' => $cart_item_key,
     'product_id'   => $product_id,
     'variation_id' => $variation_id,
     'variation'    => $variation,
     'quantity'     => $quantity,
     'data'         => $product_data, array_merged = $cart_item_key );
     
-----------------
get_items_from_cart() {
		$this->items = array();
		foreach ( $this->cart->get_cart() as $cart_item_key => $cart_item ) {
			$item                          = $this->get_default_item_props();
			$item->key                     = $cart_item_key;
			$item->object                  = $cart_item;
			$item->tax_class               = $cart_item['data']->get_tax_class();
			$item->taxable                 = 'taxable' === $cart_item['data']->get_tax_status();
			$item->price_includes_tax      = wc_prices_include_tax();
			$item->quantity                = $cart_item['quantity'];
			$item->price                   = wc_add_number_precision_deep( $cart_item['data']->get_price() * $cart_item['quantity'] );
			$item->product                 = $cart_item['data'];
			$item->tax_rates               = $this->get_item_tax_rates( $item );
			$this->items[ $cart_item_key ] = $item;
		}
	}
	

Add New Hook/Filter/Reference

HOOK FILE(S)
post_row_actions product.php, shop_coupon.php
the_excerpt product.php
woocommerce_debug_posting woocommerce-admin-status.php
woocommerce_reports_order_statuses woocommerce-admin-reports.php, woocommerce-admin-reports.php, woocommerce-admin-reports.php, woocommerce-admin-reports.php, woocommerce-admin-reports.php, woocommerce-admin-reports.php
woocommerce_reports_stock_overview_products woocommerce-admin-reports.php
woocommerce_screen_ids woocommerce-admin-init.php
woocommerce_settings_tabs_array woocommerce-admin-settings.php
From: Email
Subject: What?
Message: