I am new to wordpress, trying to develop a wordpress plugin where I need to call a woocommerce method add_to_cart
from the class woocommerce/includes/class-wc-cart.php
. Is there any way to do that ?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
WooCommerce declares a handy globlal
WC()
that you can use inside your plugin to call its functions.Add the following code to your plugin
Above code will automatically add a product to the cart when you visit the single product page. Here's a list of hooks & filters offered by WooCommerce that you can hook into.