Posts

Showing posts with the label Code Snippets

Create WooCommerce Custom Accounts Page

Image
In this post I am going to show you how to create WooCommerce custom accounts page. We will create a new accounts tab and a page linked to it. Create New Account Tab We will create a new tab “CI Custom Endpoint” and assigned it to the items array. Our custom tab menu function will be hooked to woocommerce_account_menu_items. The logout menu tab is passed to unset() function because we want our Custom Tab before it. Later again Logout tab is added to the items[] array to display it in the end . Flush Rewrite Rules We need to register a new endpoint in WordPress using the add_rewrite_endpoint() function. Also register it using the query_vars filter. Endpoints are an extra part in the site URL that detect and show different content of page. Custom Accounts Page In last step the ci_custom_endpoint_content() function includes custom page and is hooked to endpoint. The code within this function will display tabs data. You can add code directly to function or can add a custom page. The page ...

Update WooCommerce Checkout Total with Postcode Field

Image
Sometime you want to update the checkout total based on a specific field. e.g how to update WooCommerce checkout total with postcode field. Enter the value in billing_postcode field and as you blur. The jQuery( ‘body’ ).trigger( ‘update_checkout’ ); will be triggered and the checkout total will be updated. Use the following code snippet within theme functions.php   Custom WooCommerce Plugin Development   Flatsome Theme Customization   WooCommerce Checkout Page Fields   Checkout Field Editor  

Send Additional WooCommerce Email

Image
Sometime you want to send additional WooCommerce email to certain address or to third party. To send such emails is not quite hard, if you know the right hooks. We need to hook our function when action is triggered and order is set to cancelled. We use hook woocommerce_order_status_processing_to_cancelled_notification It is triggered when order status changed from processing to cancelled. The hook accepts 1 parameter which is the $order_id. You can use this hook when orders are cancelled in case of some issues occurs e.g Payment Failed. The WooCommerce mailer class is loaded e.g WC()->mailer(); It has following parameters. $recipient: Email address of the person to notify. $subject: Subject of your email. $content: Content of Email. The ci_get_cancelled_notification_content() functions fetches our email contents. $headers: Tells mailer its HTML email. The wc_get_template_html() is a WooCommerce function that loads email template with contents passed in array. Add the following cod...

WooCommerce Auto Update Cart When Quantity Changes

Image
Do you want WooCommerce auto update cart when quantity changes. Yes, with a simple php function with two lines of JQuery and the result is great! When you change the product quantity this JQuery code will update your cart data jQuery(“[name=’update_cart’]”).trigger(“click”); Use one of two code snippet within theme functions.php   Custom WooCommerce Plugin Development   7 Things You Should Never Do With Your WooCommerce Store   Flatsome Theme Customization   WooHero WooCommerce Store Customizer  

Product Tabs in WooCommerce

Image
In this post I am going to show you how to handle product tabs in WooCommerce. By default WooCommerce have ‘Description’, ‘Reviews’ and ‘Additional Information’ tabs. We will add custom tabs, remove & rename existing one’s and other stuff with WooCommerce product tabs. Add Custom Product Data Tab Use the following code snippet will add a custom product tab. Add Custom Physical Product Data Tab Use the following code snippet will add a custom product tab but it will only be displayed for physical products. Rename Product Data Tab Use the following code snippet will rename a product tab. Reorder Product Data Tab Use the following code snippet will reorder the product tabs. Remove Product Data Tab Use the following code snippet will remove a product tab. Customize Product Description Data Tab Use the following code snippet will customize the product description tab. There are some plugins available that can add product tabs. Before using always check the star rating for that plugin. ...

WooCommerce Hooks Actions & Filters

Image
In this post I’m going to show how to use WooCommerce Hooks actions & filters for core plugin customization.  Hooks are of two types Action and Filter. Hooks are snippets of code that can be placed into your WordPress theme’s functions.php file or even added into a custom plugin. Action Hooks Action hooks are triggered when an event takes place, such as a user logged in or a custom action that you define in your theme or plugin.   We can create our own custom action hooks within plugin or theme using do_action() function. The function hooked to that action will run at that point in the code.   Filter Hooks Filter Hooks are used to modify data at runtime. The main difference between Action and Filter hook is, Filter Hook always returns a modified data value while Action Hook just triggers the code at that point in the code.   The apply_filter() functions apply filter to the the existing code. Later we can modify that code via add_filter() function. For WooCommerc...