Woocommerce add Custom Shipping Fee

Use your discretion and adjust the function as you need it. It should make sense when you read the function. It currently sets a shipping fee based on the total cost of the cart.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// ADD SHIPPING COST
function woo_add_cart_fee() {
if (WC()->cart->cart_contents_total > 1000) {
WC()->cart->add_fee( __('Shipping', 'woocommerce'), 100 );
}else{
WC()->cart->add_fee( __('Shipping', 'woocommerce'), 100 );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
// ADD SHIPPING COST function woo_add_cart_fee() { if (WC()->cart->cart_contents_total > 1000) { WC()->cart->add_fee( __('Shipping', 'woocommerce'), 100 ); }else{ WC()->cart->add_fee( __('Shipping', 'woocommerce'), 100 ); } } add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
// ADD SHIPPING COST
function woo_add_cart_fee() {
    
    if (WC()->cart->cart_contents_total > 1000) {
        WC()->cart->add_fee( __('Shipping', 'woocommerce'), 100 );
    }else{
        WC()->cart->add_fee( __('Shipping', 'woocommerce'), 100 );
    }
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
PHP Start A Session and Set Session Variable
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
session_start();
if (!isset($_SESSION['splash'])) {
$_SESSION['splash'] = "active";
echo "Session has been started";
}else {
echo "Session is currently active";
// $_SESSION['splash'] = "active";
}
?>
<?php session_start(); if (!isset($_SESSION['splash'])) { $_SESSION['splash'] = "active"; echo "Session has been started"; }else { echo "Session is currently active"; // $_SESSION['splash'] = "active"; } ?>
<?php 
  session_start();
  if (!isset($_SESSION['splash'])) {
    $_SESSION['splash'] = "active";
    echo "Session has been started";
  }else {
    echo "Session is currently active";
    // $_SESSION['splash'] = "active";
  }
?>
WP_QUERY

Calling your Query While or Foreach

While

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php $query = new WP_Query($args); ?>
<?php while ( $query->have_posts() ) : the_post(); ?>
<div>
<?php
$query->the_post();
get_template_part( 'content', get_post_format() );
?>
</div>
<?php endwhile; ?>
<?php $query = new WP_Query($args); ?> <?php while ( $query->have_posts() ) : the_post(); ?> <div> <?php $query->the_post(); get_template_part( 'content', get_post_format() ); ?> </div> <?php endwhile; ?>
<?php $query = new WP_Query($args); ?>
<?php while ( $query->have_posts() ) : the_post(); ?>
  <div>
      <?php 
      	$query->the_post();        
        get_template_part( 'content', get_post_format() ); 
    ?>
  </div>
<?php endwhile; ?>

Foreach

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$query = new WP_Query( array( 'post_type' => 'page' ) );
$posts = $query->posts;
foreach($posts as $post) {
// Do your stuff, e.g.
// echo $post->post_name;
}
$query = new WP_Query( array( 'post_type' => 'page' ) ); $posts = $query->posts; foreach($posts as $post) { // Do your stuff, e.g. // echo $post->post_name; }
$query = new WP_Query( array( 'post_type' => 'page' ) );
$posts = $query->posts;

foreach($posts as $post) {
    // Do your stuff, e.g.
    // echo $post->post_name;
}

By Term

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$args['tax_query'][] =
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'category slug must go here'
);
$args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'category slug must go here' );
$args['tax_query'][] =
    array(
    'taxonomy' => 'category',
    'field' => 'slug',
    'terms' => 'category slug must go here'
  );

By Post Type

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$args['post_type'] = 'courses';
$args['post_type'] = 'courses';
$args['post_type'] = 'courses';

By Post Status

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$args['post_status'] = 'publish';
$args['post_status'] = 'publish';
$args['post_status'] = 'publish';

Posts Per Page

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$args['posts_per_page'] = 10;
$args['posts_per_page'] = 10;
$args['posts_per_page'] = 10;

Posts By Category

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$args['cat'] = $_GET['category-id'];
$args['cat'] = $_GET['category-id'];
$args['cat'] = $_GET['category-id'];
Start Making A WordPress Plugin From Scratch

This post requires developer discretion. The file names are written as an example for this post. As long as you make sure your files are been linked up correctly, you can name your files whatever you like. There’s loads of comments to help you along the way.
You need 2 files for this process. Unless you want to set a custom Icon then you will need 3 files.
All of these files need to be inside their own folder in order to build up your plugin.


Plugin Folder :

plugin-index.php
main-page.php
Your ICON. (Your icon dimensions must be 16×16)


plugin-index.php is your starting file. This is the file where your plugin starts. And it will contain the following.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/*
Plugin Name: coverweb Custom Woocommerce Extra's
*/
// Main Menu Tabs
// add_menu_page();
//(Sub Menu Tabs) List of possible pages you can add from pre built wp stuff (using the below functions will add a sub menu into the matching page tab )
// add_dashboard_page();
// add_posts_page();
// add_pages_page();
// add_comments_page();
// add_plugins_page();
// add_users_page();
// add_theme_page(); /*for the appearance tab*/
// add_management_page(); /*for the tools tab*/
// add_options_page(); /*for the settings tab*/
function my_admin_menu() {
//(This will aqppear in place of the browser tab name)
$page_title = 'Clear Stock';
//(This will aqppear in place of the tab name)
$menu_title = 'Clear Stock';
//(Capability is required to display plugin menu in admin panel)
$capability = 'manage_options';
//(Menu Slug is the text that refers this plugin page. It displays as page name in URL We always CALL a plugin page by the menu slug)
$menu_slug = 'clear-stock';
//(This calls the function below which has been set up to include a page that is in the plugin folder.)
$function = 'clear_stock_function';
//(This will get the icon you upload into your plugin file, Leave blank like so '' if you don't have an ICON and you will get a default Cog Icon)
$icon_url = plugins_url('recycle.png',__FILE__);
//(The position is just an integer. The higher you go. The lower down the position is in the admin section of wordpress)
$position = 56;
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
}
add_action( 'admin_menu', 'my_admin_menu' );
function clear_stock_function(){
include ("main-page.php"); //this must be inside your plugins folder
}
/* Plugin Name: coverweb Custom Woocommerce Extra's */ // Main Menu Tabs // add_menu_page(); //(Sub Menu Tabs) List of possible pages you can add from pre built wp stuff (using the below functions will add a sub menu into the matching page tab ) // add_dashboard_page(); // add_posts_page(); // add_pages_page(); // add_comments_page(); // add_plugins_page(); // add_users_page(); // add_theme_page(); /*for the appearance tab*/ // add_management_page(); /*for the tools tab*/ // add_options_page(); /*for the settings tab*/ function my_admin_menu() { //(This will aqppear in place of the browser tab name) $page_title = 'Clear Stock'; //(This will aqppear in place of the tab name) $menu_title = 'Clear Stock'; //(Capability is required to display plugin menu in admin panel) $capability = 'manage_options'; //(Menu Slug is the text that refers this plugin page. It displays as page name in URL We always CALL a plugin page by the menu slug) $menu_slug = 'clear-stock'; //(This calls the function below which has been set up to include a page that is in the plugin folder.) $function = 'clear_stock_function'; //(This will get the icon you upload into your plugin file, Leave blank like so '' if you don't have an ICON and you will get a default Cog Icon) $icon_url = plugins_url('recycle.png',__FILE__); //(The position is just an integer. The higher you go. The lower down the position is in the admin section of wordpress) $position = 56; add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position); } add_action( 'admin_menu', 'my_admin_menu' ); function clear_stock_function(){ include ("main-page.php"); //this must be inside your plugins folder }
  /*
  Plugin Name: coverweb Custom Woocommerce Extra's
  */

  // Main Menu Tabs
    // add_menu_page();
  //(Sub Menu Tabs) List of possible pages you can add from pre built wp stuff (using the below functions will add a sub menu into the matching page tab )
    // add_dashboard_page();
    // add_posts_page();
    // add_pages_page();
    // add_comments_page();
    // add_plugins_page();
    // add_users_page();
    // add_theme_page();  /*for the appearance tab*/
    // add_management_page();  /*for the tools tab*/
    // add_options_page();  /*for the settings tab*/

  function my_admin_menu() {
      //(This will aqppear in place of the browser tab name)
      	$page_title = 'Clear Stock'; 
      //(This will aqppear in place of the tab name)
      	$menu_title = 'Clear Stock'; 
      //(Capability is required to display plugin menu in admin panel)
      	$capability = 'manage_options';
      //(Menu Slug is the text that refers this plugin page. It displays as page name in URL We always CALL a plugin page by the menu slug)
        $menu_slug = 'clear-stock';
      //(This calls the function below which has been set up to include a page that is in the plugin folder.)
        $function = 'clear_stock_function';
      //(This will get the icon you upload into your plugin file, Leave blank like so '' if you don't have an ICON and you will get a default Cog Icon)
        $icon_url = plugins_url('recycle.png',__FILE__);
      //(The position is just an integer. The higher you go. The lower down the position is in the admin section of wordpress)
        $position = 56;
      add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
  }
  add_action( 'admin_menu', 'my_admin_menu' );

  function clear_stock_function(){
    include ("main-page.php"); //this must be inside your plugins folder
  }

main-page.php is where you start writing your plugin content that will show up in your admin section. (Just start with the code below to get started)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<title>Custom Plugin</title>
</head>
<body>
<div>
<h1>Your new plugin Is ready to start been developed.</h1>
</div>
</body>
</html>
<!DOCTYPE html> <html> <head> <title>Custom Plugin</title> </head> <body> <div> <h1>Your new plugin Is ready to start been developed.</h1> </div> </body> </html>
<!DOCTYPE html>
<html>
<head>
  <title>Custom Plugin</title>
</head>
<body>
  <div>
    <h1>Your new plugin Is ready to start been developed.</h1>
  </div>
</body>
</html>

Your ICON : Must be 16×16.
A word of advice… make sure it’s a light icon that doesn’t disappear in the dark default wordpress dark grey colour.

Step 1 Adding a Plugin
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function my_admin_menu() {
$page_title = 'Clear Stock';
$menu_title = 'Clear Stock';
$capability = 'manage_options';
$menu_slug = '/clear_stock';
$function = 'clear_stock';
$icon_url = '';
$position = -1;
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
}
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() { $page_title = 'Clear Stock'; $menu_title = 'Clear Stock'; $capability = 'manage_options'; $menu_slug = '/clear_stock'; $function = 'clear_stock'; $icon_url = ''; $position = -1; add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position); } add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
    $page_title = 'Clear Stock';
    $menu_title = 'Clear Stock';
    $capability = 'manage_options';
    $menu_slug = '/clear_stock';
    $function = 'clear_stock';
    $icon_url = '';
    $position = -1;
    add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
}
add_action( 'admin_menu', 'my_admin_menu' );

Search

Your Favourite Posts

  • Your favorites will be here.

Latest Content

© Garth Baker 2025 All rights reserved.

Pin It on Pinterest

Garth Baker
en
af
sq
am
ar
hy
az
eu
be
bn
bs
bg
ca
ceb
ny
zh-CN
zh-TW
co
hr
cs
da
nl
en
eo
et
tl
fi
fr
fy
gl
ka
de
el
gu
ht
ha
haw
iw
hi
hmn
hu
is
ig
id
ga
it
ja
jw
kn
kk
km
ko
ku
ky
lo
la
lv
lt
lb
mk
mg
ms
ml
mt
mi
mr
mn
my
ne
no
ps
fa
pl
pt
pa
ro
ru
sm
gd
sr
st
sn
sd
si
sk
sl
so
es
su
sw
sv
tg
ta
te
th
tr
uk
ur
uz
vi
cy
xh
yi
yo
zu
Share This