1// $cart conditionals (if)
2WC()->cart->is_empty()
3WC()->cart->needs_payment()
4WC()->cart->show_shipping()
5WC()->cart->needs_shipping()
6WC()->cart->needs_shipping_address()
7WC()->cart->display_prices_including_tax()
8
9// Get $cart totals
10WC()->cart->get_cart_contents_count();
11WC()->cart->get_cart_subtotal();
12WC()->cart->subtotal_ex_tax;
13WC()->cart->subtotal;
14WC()->cart->get_displayed_subtotal();
15WC()->cart->get_taxes_total();
16WC()->cart->get_shipping_total();
17WC()->cart->get_coupons();
18WC()->cart->get_coupon_discount_amount( 'coupon_code' );
19WC()->cart->get_fees();
20WC()->cart->get_discount_total();
21WC()->cart->get_total();
22WC()->cart->total;
23WC()->cart->get_tax_totals();
24WC()->cart->get_cart_contents_tax();
25WC()->cart->get_fee_tax();
26WC()->cart->get_discount_tax();
27WC()->cart->get_shipping_total();
28WC()->cart->get_shipping_taxes();
29
30// Loop over $cart items
31foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
32 $product = $cart_item['data'];
33 $product_id = $cart_item['product_id'];
34 $quantity = $cart_item['quantity'];
35 $price = WC()->cart->get_product_price( $product );
36 $subtotal = WC()->cart->get_product_subtotal( $product, $cart_item['quantity'] );
37 $link = $product->get_permalink( $cart_item );
38 // Anything related to $product, check $product tutorial
39 $attributes = $product->get_attributes();
40 $whatever_attribute = $product->get_attribute( 'whatever' );
41 $whatever_attribute_tax = $product->get_attribute( 'pa_whatever' );
42 $any_attribute = $cart_item['variation']['attribute_whatever'];
43 $meta = wc_get_formatted_cart_item_data( $cart_item );
44}
45
46// Get $cart customer billing / shipping
47WC()->cart->get_customer()->get_billing_first_name();
48WC()->cart->get_customer()->get_billing_last_name();
49WC()->cart->get_customer()->get_billing_company();
50WC()->cart->get_customer()->get_billing_email();
51WC()->cart->get_customer()->get_billing_phone();
52WC()->cart->get_customer()->get_billing_country();
53WC()->cart->get_customer()->get_billing_state();
54WC()->cart->get_customer()->get_billing_postcode();
55WC()->cart->get_customer()->get_billing_city();
56WC()->cart->get_customer()->get_billing_address();
57WC()->cart->get_customer()->get_billing_address_2();
58WC()->cart->get_customer()->get_shipping_first_name();
59WC()->cart->get_customer()->get_shipping_last_name();
60WC()->cart->get_customer()->get_shipping_company();
61WC()->cart->get_customer()->get_shipping_country();
62WC()->cart->get_customer()->get_shipping_state();
63WC()->cart->get_customer()->get_shipping_postcode();
64WC()->cart->get_customer()->get_shipping_city();
65WC()->cart->get_customer()->get_shipping_address();
66WC()->cart->get_customer()->get_shipping_address_2();
67
68// Other stuff
69WC()->cart->get_cross_sells();
70WC()->cart->get_cart_item_tax_classes_for_shipping();
71WC()->cart->get_cart_hash();
72WC()->cart->get_customer();
73
1
2// To change add to cart text on single product page
3add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );
4function woocommerce_custom_single_add_to_cart_text() {
5 return __( 'Buy Now', 'woocommerce' );
6}
7// To change add to cart text on product archives(Collection) page
8add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
9function woocommerce_custom_product_add_to_cart_text() {
10 return __( 'Buy Now', 'woocommerce' );
11}