Skip to content

Instantly share code, notes, and snippets.

View finalwebsites's full-sized avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / uitverkocht-uitschakelen.php
Created February 20, 2022 16:04
WooCommerce product variaties uitschakelen wanneer deze zijn uitverkocht
<?php
// plaats deze code in het functions.php bestand van je child thema
add_filter( 'woocommerce_variation_is_active', 'fws_disable_variations_out_of_stock', 10, 2 );
function fws_disable_variations_out_of_stock( $is_active, $variation ) {
if ( ! $variation->is_in_stock() ) return false;
return $is_active;
}
@finalwebsites
finalwebsites / Admin_columns_variation_name.php
Created January 31, 2022 11:14
Admin Columns: Add variation name to column
<?php
function ac_column_value_usage( $col_value, $id, AC\Column $column ) {
if ('column-wc-product_details' == $column->get_type()) {
$order = wc_get_order( $id );
foreach ( $order->get_items() as $item_id => $item ) {
if ( $item->get_variation_id() ) {
$product = $item->get_product();
foreach ( $product->get_attributes() as $attribute => $value ) {
$name = term_exists( $value, $attribute ) ? get_term_by( 'slug', $value, $attribute )->name : $value;
$col_value = $col_value .'<br>' . $name;
@finalwebsites
finalwebsites / functions.php
Created July 12, 2021 06:21
reCaptacha for HTML Forms
<?php
function fws_enqueue_recaptcha() {
$sitekey = mysitekey';
wp_enqueue_script( 'fws-recaptcha', '//www.google.com/recaptcha/api.js?render=' . $sitekey, null, null, true );
}
add_action( 'wp_enqueue_scripts', 'oceanwp_child_enqueue_parent_style' );
@finalwebsites
finalwebsites / check-email-list.php
Created July 6, 2021 06:58
Check your email list with the email validation service from mailboxlayer
<?php
set_time_limit(0);
ini_set('memory_limit', '2048M'); // if your list is very long
$api_key = 'PLACE HERE YOUR API';
$fp = fopen('emailchecked.csv', 'w');
fputcsv($fp, array('Email address', 'Valid MX', 'Valid SMTP', 'Score'));
$count = 0;
@finalwebsites
finalwebsites / wordpress-instellingen-afbeeldingen.php
Last active May 31, 2021 09:44
"Overbodige" afbeeldingsafmetingen in WordPress uitschakelen
<?php
// disable the generation of large image sizes
function fws_disable_image_sizes($sizes) {
unset($sizes['medium_large']);
unset($sizes['1536x1536']); // 2x medium-large size
unset($sizes['2048x2048']); // 2x large size
return $sizes;
}
add_action('intermediate_image_sizes_advanced', 'fws_disable_image_sizes');
@finalwebsites
finalwebsites / form-checkout.php
Created January 24, 2021 09:25
WooCommerce afrekenpagina met twee kolommen voor de klant- en ordergegevens
<?php
/**
* Checkout Form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@finalwebsites
finalwebsites / wp_add_modified_date_column.php
Created December 12, 2020 11:04
Add a modified date column to your posts & pages list in WordPress
<?php
// Register Modified Date Column for both posts & pages
function modified_column_register( $columns ) {
$columns['Modified'] = __( 'Modified Date', 'show_modified_date_in_admin_lists' );
return $columns;
}
add_filter( 'manage_posts_columns', 'modified_column_register' );
add_filter( 'manage_pages_columns', 'modified_column_register' );
function modified_column_display( $column_name, $post_id ) {
@finalwebsites
finalwebsites / categories_with_childs.php
Created August 23, 2020 13:19
Hierarchical categories for the plugin WooCommerce Google Product feed
<?php
add_filter( 'woocommerce_gpf_elements_google', function ( $elements, $product_id, $variation_id ) {
$elements['product_type'] = array_map( function ( $item ) {
if ( empty( $item->parent ) ) {
return $item->name;
}
$parent_list = array_reverse( get_ancestors( $item->term_id, 'product_cat', 'taxonomy' ) );
$parent_list = array_map( function ( $term_id ) {
$term = get_term( $term_id, 'product_cat' );
@finalwebsites
finalwebsites / cf7_recaptcha.php
Created August 23, 2020 13:12
Dequeue cf7 JavaScript and reCaptcha scripts and preventing them from loading everywhere.
<?php
function my_register_cf7_js() {
// Dequeue cf7 and recaptcha scripts, preventing them from loading everywhere
add_filter( 'wpcf7_load_js', '__return_false' ); // Might as well use their filter
wp_dequeue_script( 'google-recaptcha' );
// If current post has cf7 shortcode, enqueue!
global $post;
if ( isset( $post->post_content ) AND has_shortcode( $post->post_content, 'contact-form-7' ) ) {
@finalwebsites
finalwebsites / add-content-storefront.php
Last active October 8, 2023 14:51
Voorbeelden voor WordPress action en filter hooks
<?php
add_action( 'storefront_header', 'ctheme_storefront_header_content', 40 );
function ctheme_storefront_header_content() {
echo '
<div class="header-usp">
Gratis verzending - Voor 14 uur besteld? Volgende dag bezorgt.
</div>';
}