Do something after WooCommerce order completed

If you want to do something after WooCommerce order completed then use this code.

woocommerce_order_status_completed action hook is a built-in hook of WooCommerce. It allows you to execute a function as when the order is completed. Add your stuff in inside of my_function().

add_action( 'woocommerce_order_status_completed', 'my_function' );
/*
 * Do something after WooCommerce sets an order on completed
 */
function my_function($order_id) {
	
	// order object (optional but handy)
	$order = new WC_Order( $order_id );
	// do some stuff here
	
}

Have any doubt, then comment here!

Create a Custom WordPress Plugin

To start, create a new folder in your “wp-content/plugins” folder called “my-plugin”. Then create a new file within this folder called “myplugin.php” and place this code:

<?php
/*
Plugin Name: my plugin
Plugin URL: https://www.boopathirajan.com
Description: A simple WordPress plugin
Version: 1.0
Author: Boopathi Rajan
Author URI: https://www.boopathirajan.com
*/
?>

If you refresh your administration panel’s plugin page, you’ll now see our plugin listed along with the other ones.Let’s go and activate our plugin by clicking Activate to the right of the plugin entry.

Have any doubt, then comment here!

How to add wordpress color picker in custom plugin development

WordPress has added a color picker in the core code from WordPress v3.5.Plugin developers can now take advantage of this and add a color picker easily in their plugin

How to Add Color Picker

Step 1) Create a java script named as color-script.js and place this code:

jQuery(document).ready(function($){
var myOptions = {
// you can declare a default color here,
// or in the data-default-color attribute on the input
defaultColor: false,
// a callback to fire whenever the color changes to a valid color
change: function(event, ui){},
// a callback to fire when the input is emptied or an invalid color
clear: function() {},
// hide the color picker controls on load
hide: true,
// show a group of common colors beneath the square
// or, supply an array of colors to customize further
palettes: true
};
$('.my-color-field').wpColorPicker(myOptions);
});

Step 2) Enqueue the “wp-color-picker” jquery script


add_action( 'admin_enqueue_scripts', 'mw_enqueue_color_picker' );
function mw_enqueue_color_picker( $hook_suffix ) {
// first check that $hook_suffix is appropriate for your admin page
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'my-script-handle', plugins_url('js/color-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}

My plugin now has a color-script.js file that has declared wp-color-picker as a dependency. We can now use the wpColorPicker jQuery method inside it.

Step 3) Add an input (example: text input) to the interface where you want the color picker

<input type="text" value="#abc" class="my-color-field"/>

You can also specify a default color for the field (this will be selected by default):

<input type="text" value="#bada55" data-default-color="#abc" class="my-color-field"/>

That’s it. Your users will now be able to choose a color from the color picker

Have any doubt, then comment here!

Add scripts to the wordpress header using custom plugin

If you would like to add scripts between <head></head> tag then you have to use wp_head() function.for example

Add the following code to your plugin

// Add scripts to wp_head()
function child_theme_head_script() {
    // Your code here
}
add_action( 'wp_head', 'child_theme_head_script' );

That’s it.Code added to wp_head() will be run just before the closing </head> tag.

Have any doubt, then comment here!