Category: woocommerce

woocommerce

Display coupons used in an order in woocommerce

Use any order hooks.  here we get the deatils of coupen once cancelled the order from orders list add_action(‘woocommerce_order_status_cancelled’, ‘order_cancelled_woo’); order_cancelled_woo($order_id){ $order = new WC_Order($order_id); $coupens= $order->get_used_coupons(); file_put_contents(‘filename1.txt’,print_r($coupens,true)); }

Woocommerce Hooks

woocommerce_order_status_{action}

“woocommerce_order_status_” used to define a callback for any order status changed. It works once we changed the order status So here we need to specify the action. Usually used once we declare a new order status. Sample code is for “invoice” action add_action(‘woocommerce_order_status_invoice, ‘custom_order_action’ );   function custom_order_action($order_statuses) { /* code execute after status changed…

Woocommerce Hooks

woocommerce_order_action_ {action}

“woocommerce_order_action_” used to define a callback for any order action occurred. It works once we changed the order action So here we need to specify the action. Usually used once we declare a new order status. Sample code is for “invoice” action add_action(‘woocommerce_order_action_invoice, ‘custom_order_action’ );   function custom_order_action($order_statuses) { /* code execute after action triggered…

Woocommerce Hooks

wc_order_statuses

This hook, used to add a new order status in Order list of woocommerce. Using this hook we can add a new action in “Order Satus” in Orders . add_action(‘wc_order_statuses’, ‘custom_order_status’ ); fnction custom_order_action($order_statuses) { $order_statuses[“wc-shipped”]=”shipped”; return $order_statuses; }

Woocommerce Hooks

woocommerce_order_actions

This hook, used to add a new order action in Order list of woocommerce. Using this hook we can add a new action in “Order Action” in Orders . add_action( ‘woocommerce_order_actions’, ‘custom_order_action’ ); function custom_order_action($actions) { $actions[‘shipped’] = __( ‘Shipped’, ‘wp’); return $actions; }

Woocommerce Hooks

woocommerce_cart_item_name

This hook, works for each product in cart. Its arguments are, name, cart item details and a item key. add_filter(‘woocommerce_cart_item_name’,’cart_single_item’); function cart_single_item($product_name, $values, $cart_item_key )   { echo $product_name; print_r($values); print_r($cart_item_key); } If you need to append anything in each cart item, use this filter.  

Woocommerce Hooks

woocommerce_cart_updated

This hook, works when a cart is updated. If you want to recalculate anything in each cart updation(quantity change, product adding, deleting) use this filter add_action( ‘woocommerce_thankyou’, ‘update_cart’ ); function ‘update_cart ($order_id){ }

Woocommerce Hooks

woocommerce_thankyou

This hook, works when a user complete the order. add_action( ‘woocommerce_thankyou’, ‘complte_order’ ); function complte_order($order_id){ } Use this hook, if you want to change any code once user complete order process.

Woocommerce Hooks

woocommerce_calculate_totals

This hook, works when total calculate. add_action(‘woocommerce_calculate_totals’,’calculate_totals’); function calculate_totals($totals){ global $woocommerce; } Use this hook, if you want to change any order total calculations.  

Woocommerce Hooks

woocommerce_order_status_cancelled

If order status updated to ‘cancelled’ execute ‘failed_status_ cancel’ add_action(‘woocommerce_order_status_cancelled’, ‘failed_status_cancel’);  

Load More