Skip to content

Instantly share code, notes, and snippets.

View paaljoachim's full-sized avatar

Paal Joachim Romdahl paaljoachim

View GitHub Profile
paaljoachim / functions.php
Last active February 28, 2024 21:41
WooCommerce show/hide products based on if the user is logged inn or logged out.
add_action( 'woocommerce_product_query', 'show_hide_products_category_shop' );
function show_hide_products_category_shop( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
if ( is_user_logged_in() ) {
paaljoachim / functions.php
Created October 3, 2019 21:28
WooCommerce cart: Change shipping rate based on contents count and another example based on total purchased.
// Change shipping based on quantity purchased.
add_filter( 'woocommerce_package_rates', 'bbloomer_woocommerce_tiered_shipping', 10, 2 );
function bbloomer_woocommerce_tiered_shipping( $rates, $package ) {
$threshold1 = 2;
$threshold2 = 3;
if ( WC()->cart->get_cart_contents_count() < $threshold1 ) {
unset( $rates['flat_rate:6'], $rates['flat_rate:8'] );
} elseif ( WC()->cart->get_cart_contents_count() < $threshold2 ){
paaljoachim / functions.php
Last active March 7, 2023 18:50
WooCommerce: Adding multiple custom fields to the order notes area in the checkout page
/* 1. Adds a custom field. NB. I am using some Norwegian words in the below text.
* 2. Then adds a validate error message if person does not fill out the field.
* 3. Then adds the custom field to the order page.
add_action( 'woocommerce_before_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
paaljoachim / functions.php
Last active September 27, 2022 18:00
WooCommerce dropdown product quantity. It also correctly adds the correct minimum quantity when pressing the Add to Cart in the Shop page.
/** Initial code from:
As the code did not fully work I received help from Helga the Viking
with this gist:
* Change the quantity input to select.
* @param array $args Args for the input.
* @param WC_Product|null $product Product.
* @param boolean $echo Whether to return or echo|string.
* @return string
paaljoachim / functions.php
Last active May 29, 2022 00:49
Tutorial: WooCommerce Checkout: Add multiple custom fields to billing area. This code adds priority placement of field. Shows the custom fields in the backend Order Details screen and in e-mails to the admin and customer. I have also adjusted the checkbox field to give a text result instead of a value of 1. Checkbox is also pre-selected.
/* --------- Adds custom fields using filters. ------
The below custom fields shows various types one can use.
It is then displayed in the backend Order Details page and in admin and customer e-mails.
Checkboxes by default result only show the number 1 when clicked. I have added code so that when the a checkbox is clicked it will
show text such as On and Yes. Checkbox is also pre-selected.
// Initial inspiration:
// My Custom Fields
paaljoachim / genesis-featured-image.php
Last active April 16, 2022 14:52
Featured image for Genesis themes. 1. Sets the featured image. 2. If no featured image get image from category. 3. If no category image then get the first post image. 4. If no post image or category image then sets a fallback image.
paaljoachim / add-link-top-admin-menu.php
Last active March 25, 2022 07:50
Adjusting the WordPress top admin toolbar
paaljoachim / comment-notes-after
Last active September 25, 2021 08:33
Comments phrase adjustments - Genesis code snippets
// Add or remove notes after the comment box
add_filter( 'comment_form_defaults', 'sp_remove_comment_form_allowed_tags' );
function sp_remove_comment_form_allowed_tags( $defaults ) {
$defaults['comment_notes_after'] = 'An extra comment';
return $defaults;
paaljoachim / Ninja-Forms-CSS.css
Last active November 15, 2020 06:00
Showing Ninja Forms HTML code and a styled CSS form.
/* STYLING NINJA FORMS - add to your stylesheet and adjust */
/* The full form */
#ninja_forms_form_1_wrap {
background-color: #f89a16;
padding: 20px;
border: 2px solid #ccc;
border-radius: 8px;
box-shadow: 0px 3px 5px #444;
paaljoachim / welcome-panel-php
Last active January 23, 2020 13:46
Creating a new welcome Dashboard panel. I made a tutorial on adding a Dashboard widget:
*Add a custom Welcome Dashboard Panel
function my_welcome_panel() {
<div class="top-welcome-panel-content">
<div class="top-welcome-panel-logo" style="height: 120px; padding: 5px;text-align: center;">
<!-- Adds a logo top left-->