Skip to content

Instantly share code, notes, and snippets.

Avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / form-checkout.php
Created Jan 24, 2021
WooCommerce afrekenpagina met twee kolommen voor de klant- en ordergegevens
View form-checkout.php
<?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 Dec 12, 2020
Add a modified date column to your posts & pages list in WordPress
View wp_add_modified_date_column.php
<?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 Aug 23, 2020
Hierarchical categories for the plugin WooCommerce Google Product feed
View categories_with_childs.php
<?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 Aug 23, 2020
Dequeue cf7 JavaScript and reCaptcha scripts and preventing them from loading everywhere.
View cf7_recaptcha.php
<?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 Aug 16, 2020
Voorbeelden voor blogpost over WordPress action en filter hooks https://childtheme.nl/wordpress-action-filter-hooks/
View add-content-storefront.php
<?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>';
}
@finalwebsites
finalwebsites / stock_status_names.php
Created Jul 3, 2020
Different stock status names for your WooCommerce product detail page
View stock_status_names.php
<?php
/*
Using this function you can use different values on the frontend while keeping the original strings or translations.
How to use:
Place the PHP code below into the functions.php file from your WordPress child theme.
If you like, change the strings inside the quotes for the $status variables.
The action hook will place the information below the add to cart button (based on the original WooCommerce template files).
*/
@finalwebsites
finalwebsites / functions.php
Created Mar 25, 2020
Store Elementor form submissions using a custom post type
View functions.php
<?php
// place this code into you child theme's functions.php file
// Do you use Advanced Custom Fields? Uncomment the next row, otherwise the custom fields meta box doesn't show up in your edit post screen
//add_filter('acf/settings/remove_wp_meta_box', '__return_false');
add_action( 'init', 'fws_elementor_submissions_post_type' );
function fws_elementor_submissions_post_type() {
$args = array(
'public' => false,
@finalwebsites
finalwebsites / check_fix_url.php
Created Mar 3, 2020
Use this function to fix the missing protocol part from an URL
View check_fix_url.php
<?php
function check_url($url) {
if (substr($url, 0, 4) != 'http') {
$url = 'http://'.$url;
}
$response = get_headers($url);
if ($response[0] == 'HTTP/1.1 200 OK') {
return $url;
} elseif (in_array(substr($response[0], 9, 3), array(302, 301))) {
foreach ($response as $r) {
@finalwebsites
finalwebsites / pagecache-php-example.php
Last active Jan 28, 2020
Example scripts for PHP caching blog post
View pagecache-php-example.php
<?php
require_once __DIR__.'/../vendor/autoload.php';
try {
$cache = new PageCache\PageCache();
$cache->config()
->setCachePath('/your/cache_path/')
->setEnableLog(true)
->setCacheExpirationInSeconds(86400);
$cache->init();
} catch (\Exception $e) {
@finalwebsites
finalwebsites / download-example.php
Last active Feb 22, 2021
PHP download file script code example
View download-example.php
<?php
echo '
<a href="http://mydomain.com/download.php?download_file=some_file.pdf">PHP download file</a>';