Skip to content

Instantly share code, notes, and snippets.

View cubehrends's full-sized avatar
🏠
Working from home

Christian Behrends cubehrends

🏠
Working from home
View GitHub Profile
@cubehrends
cubehrends / functions.php
Created April 15, 2024 09:07
Pre Get Post CPT Partner
<?php
function lp_partner_sort( $query ) {
if( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive('partner') ){
if ( isset( $_COOKIE['region'] ) && $_COOKIE['region'] !== '0' ) {
// Get the value of the "region" cookie
$region = $_COOKIE['region'];
// Set the query parameters to filter partners by the corresponding taxonomy term
@cubehrends
cubehrends / functions.php
Last active December 25, 2023 17:32
WooCommerce - Restrict Shipping Zone by Shipping Class
<?php
// Adding notice to product availability text
function wdt_extend_availability( $availability, $product ) {
$target_shipping_class = 'dropshipping';
if ( $target_shipping_class == $product->get_shipping_class() ) {
$availability .= '<p class="shipping-class-notice">Diesen Artikel versenden wir <b>nur innerhalb Deutschlands</b>.</p>';
@cubehrends
cubehrends / functions.php
Last active December 5, 2022 09:30
WooCommerce Hide Shipping when Pickup Required
<?php
function wdt_hide_shipping_when_pickup_required( $rates, $package ) {
$class_slug = 'pickup';
// Checking in cart items
foreach( WC()->cart->get_cart() as $cart_item ){
// If we find the shipping class
if( $cart_item['data']->get_shipping_class() == $class_slug ){
unset($rates['flat_rate:2']); // Remove flat rate
@cubehrends
cubehrends / peekaboo.js
Created May 31, 2022 18:35
Handles the header at webdevtrust.com
'use strict';
(function($){
let Peekaboo = {
// PROPERTIES
$window: null,
$header: null,
height: 0,
curPos: 0,
@cubehrends
cubehrends / functions.php
Created January 18, 2022 13:20
check address for required house number on WooCommerce checkout
<?php
function wdt_address_field_validation() {
$post_value = $_POST['billing_address_1'];
if ( $post_value && ! preg_match( '/[0-9]+/', $post_value ) ) {
throw new Exception( sprintf( __( 'Das Feld <strong>Straße</strong> muss eine <strong>Hausnummer</strong> beinhalten.', 'woocommerce' ) ) );
}
}
@cubehrends
cubehrends / obfuscate.sql
Last active January 5, 2022 14:06
obfuscate user data for privacy in WordPress database
UPDATE wp_users AS user
INNER JOIN wp_usermeta AS meta ON meta.user_id = user.ID
SET
user.user_email = CONCAT(SUBSTRING(MD5(RAND()), -10), "@", SUBSTRING(MD5(RAND()), -10), ".com"),
/** random strings */
user.user_pass = CONCAT("pass_", SUBSTRING(MD5(RAND()), -10)),
user.user_nicename = CONCAT("nice_", SUBSTRING(MD5(RAND()), -10)),
user.user_login = CONCAT("login_", SUBSTRING(MD5(RAND()), -10)),
user.display_name = CONCAT("display_", SUBSTRING(MD5(RAND()), -10))
/** except our admins */
@cubehrends
cubehrends / date.twig
Created November 20, 2021 11:16
Replacing English month names with German ones in a Twig missing The Intl Extension
{% set d = ( post.date | date( 'j. F Y' ) ) %}
<p>
{{ d | replace({
'January': 'Januar',
'February': 'Februar',
'March': 'März',
'May': 'Mai',
'June': 'Juni',
'July': 'Juli',
@cubehrends
cubehrends / functions.php
Last active June 3, 2021 12:22
Lieferzeit bei Lieferrückstand anpassen
<?php
add_filter( 'woocommerce_germanized_delivery_time_backorder_html', 'wdt_adjust_delivery_time_html', 10, 4 );
function wdt_adjust_delivery_time_html( $text, $product ) {
// this must be a variation if we can find a parent_id
if ( $product->get_parent_id() ) {
$id = $product->get_parent_id();
} else {
$id = $product->get_id();
}
@cubehrends
cubehrends / functions.php
Last active May 31, 2021 15:39
Alternative Lieferzeit bei Lieferrückstand mit WooCommerce und Germanized
<?php
add_action( 'woocommerce_product_options_stock_status', 'wdt_add_deliver_time_fallback' );
function wdt_add_deliver_time_fallback() {
// Lieferzeiten aus den Terms generieren
$delivery_times = get_terms( array(
'taxonomy' => 'product_delivery_time',
'hide_empty' => false,
) );
$options[''] = __( 'Keine', 'woocommerce');
foreach ($delivery_times as $key => $term) {
@cubehrends
cubehrends / functions.php
Last active May 17, 2021 15:25
Processing WooCommerce Meta Infos
<?php
add_action( 'woocommerce_process_product_meta', 'wdt_process_delivery_time_fallback', 10, 2 );
function wdt_process_delivery_time_fallback( $id, $post ){
$dtf_id = $_POST['delivery_time_fallback'];
if( $dtf_id === '' ) {
delete_post_meta( $id, '_delivery_time_fallback' );
} else {
update_post_meta( $id, '_delivery_time_fallback', $dtf_id );
}