Skip to content

Commit f038fe1

Browse files
authored
Merge pull request #1 from web-lifter/codex/setup-woocommerce-utils-plugin
Add WooCommerce Utils plugin
2 parents e3c8f97 + 5912c1f commit f038fe1

File tree

5 files changed

+174
-1
lines changed

5 files changed

+174
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
# woocommerce-utils
1+
# WooCommerce Utils
2+
3+
WooCommerce Utils is a simple plugin that adds helpful utilities for WooCommerce sites.
4+
5+
Features include:
6+
7+
- Custom **Shipped** order status.
8+
- An admin page accessible under WooCommerce that describes the plugin.
9+
10+
This repository contains the plugin files for use within WordPress.

includes/class-wc-utils-admin.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
if ( ! defined( 'ABSPATH' ) ) {
3+
exit;
4+
}
5+
6+
/**
7+
* Handle admin menu and settings.
8+
*/
9+
class WC_Utils_Admin {
10+
11+
/**
12+
* Constructor.
13+
*/
14+
public function __construct() {
15+
add_action( 'admin_menu', array( $this, 'register_menu' ) );
16+
}
17+
18+
/**
19+
* Register plugin menu.
20+
*/
21+
public function register_menu() {
22+
add_submenu_page(
23+
'woocommerce',
24+
__( 'WooCommerce Utils', 'woocommerce-utils' ),
25+
__( 'WC Utils', 'woocommerce-utils' ),
26+
'manage_woocommerce',
27+
'wc-utils',
28+
array( $this, 'render_page' )
29+
);
30+
}
31+
32+
/**
33+
* Render settings page.
34+
*/
35+
public function render_page() {
36+
?>
37+
<div class="wrap">
38+
<h1><?php esc_html_e( 'WooCommerce Utils', 'woocommerce-utils' ); ?></h1>
39+
<p><?php esc_html_e( 'This plugin adds helpful utilities for WooCommerce.', 'woocommerce-utils' ); ?></p>
40+
</div>
41+
<?php
42+
}
43+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
if ( ! defined( 'ABSPATH' ) ) {
3+
exit;
4+
}
5+
6+
/**
7+
* Implement various WooCommerce utilities.
8+
*/
9+
class WC_Utils_Features {
10+
11+
public function __construct() {
12+
add_filter( 'wc_order_statuses', array( $this, 'register_order_status' ) );
13+
add_action( 'init', array( $this, 'add_order_status' ) );
14+
}
15+
16+
/**
17+
* Register new order status.
18+
*/
19+
public function add_order_status() {
20+
register_post_status( 'wc-shipped', array(
21+
'label' => 'Shipped',
22+
'public' => true,
23+
'exclude_from_search' => false,
24+
'show_in_admin_all_list' => true,
25+
'show_in_admin_status_list' => true,
26+
'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped <span class="count">(%s)</span>', 'woocommerce-utils' )
27+
) );
28+
}
29+
30+
/**
31+
* Add to list of WC order statuses.
32+
*/
33+
public function register_order_status( $order_statuses ) {
34+
$new_order_statuses = array();
35+
36+
foreach ( $order_statuses as $key => $status ) {
37+
$new_order_statuses[ $key ] = $status;
38+
if ( 'wc-processing' === $key ) {
39+
$new_order_statuses['wc-shipped'] = _x( 'Shipped', 'WooCommerce order status', 'woocommerce-utils' );
40+
}
41+
}
42+
43+
return $new_order_statuses;
44+
}
45+
}

readme.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== WooCommerce Utils ===
2+
Contributors: example
3+
Tags: woocommerce, utilities
4+
Requires at least: 5.0
5+
Tested up to: 6.4
6+
Requires PHP: 7.0
7+
Stable tag: 1.0.0
8+
License: GPLv2 or later
9+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
10+
11+
Adds helpful utilities for WooCommerce, including a custom order status and admin page.
12+
13+
== Description ==
14+
This plugin provides small utilities for WooCommerce. Currently it adds a custom 'Shipped' order status and an admin page under WooCommerce.
15+
16+
== Installation ==
17+
1. Upload the plugin files to the `/wp-content/plugins/woocommerce-utils` directory, or install the plugin through the WordPress plugins screen directly.
18+
2. Activate the plugin through the 'Plugins' screen in WordPress.
19+
3. Navigate to WooCommerce > WC Utils to access the plugin page.
20+
21+
== Changelog ==
22+
= 1.0.0 =
23+
* Initial release.

woocommerce-utils.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Plugin Name: WooCommerce Utils
4+
* Description: Provides helpful utilities for WooCommerce.
5+
* Version: 1.0.0
6+
* Author: Example Author
7+
* Text Domain: woocommerce-utils
8+
* Domain Path: /languages
9+
*/
10+
11+
if ( ! defined( 'ABSPATH' ) ) {
12+
exit; // Exit if accessed directly.
13+
}
14+
15+
// Define plugin constants.
16+
if ( ! defined( 'WC_UTILS_VERSION' ) ) {
17+
define( 'WC_UTILS_VERSION', '1.0.0' );
18+
}
19+
if ( ! defined( 'WC_UTILS_PATH' ) ) {
20+
define( 'WC_UTILS_PATH', plugin_dir_path( __FILE__ ) );
21+
}
22+
if ( ! defined( 'WC_UTILS_URL' ) ) {
23+
define( 'WC_UTILS_URL', plugin_dir_url( __FILE__ ) );
24+
}
25+
26+
/**
27+
* Initialize the plugin.
28+
*/
29+
function wc_utils_init() {
30+
// Ensure WooCommerce is active.
31+
if ( ! class_exists( 'WooCommerce' ) ) {
32+
add_action( 'admin_notices', 'wc_utils_missing_wc_notice' );
33+
return;
34+
}
35+
36+
// Include required files.
37+
require_once WC_UTILS_PATH . 'includes/class-wc-utils-admin.php';
38+
require_once WC_UTILS_PATH . 'includes/class-wc-utils-features.php';
39+
40+
// Initialize classes.
41+
new WC_Utils_Admin();
42+
new WC_Utils_Features();
43+
}
44+
add_action( 'plugins_loaded', 'wc_utils_init' );
45+
46+
/**
47+
* Display an admin notice if WooCommerce is not active.
48+
*/
49+
function wc_utils_missing_wc_notice() {
50+
echo '<div class="notice notice-error"><p>' . esc_html__( 'WooCommerce Utils requires WooCommerce to be active.', 'woocommerce-utils' ) . '</p></div>';
51+
}
52+
53+
?>

0 commit comments

Comments
 (0)