How to use wc() in woocommerce?


by jasen , in category: PHP CMS , a month ago

How to use wc() in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , a month ago


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:
$customer = wc()->customer;

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

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

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

  1. Perform actions related to payments:
$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.