How to use wc() in woocommerce?

Member

by jasen , in category: PHP CMS , 7 months ago

How to use wc() in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 7 months ago

@jasen 

In WooCommerce, the wc() function can be used to retrieve various information and perform different actions related to the WooCommerce plugin. Here are some common use cases of the wc() function:

  1. Get the current customer's details:
1
$customer = wc()->customer;


  1. Get an instance of the cart:
1
$cart = wc()->cart;


  1. Retrieve a list of available payment gateways:
1
$payment_gateways = wc()->payment_gateways->get_available_payment_gateways();


  1. Get the current order object:
1
$order = wc()->session->get('order_awaiting_payment');


  1. Perform actions related to payments:
1
$order_id = wc()->checkout()->create_order();


These are just a few examples of how you can use the wc() function in WooCommerce. You can explore more functionalities by referring to the official WooCommerce documentation.