Skip to content

Instantly share code, notes, and snippets.

Olaf Lederer finalwebsites

View GitHub Profile
finalwebsites / stock_status_names.php
Created Jul 3, 2020
Different stock status names for your WooCommerce product detail page
View stock_status_names.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 / functions.php
Created Mar 25, 2020
Store Elementor form submissions using a custom post type
View functions.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 / 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
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 / pagecache-php-example.php
Last active Jan 28, 2020
Example scripts for PHP caching blog post
View pagecache-php-example.php
require_once __DIR__.'/../vendor/autoload.php';
try {
$cache = new PageCache\PageCache();
} catch (\Exception $e) {
finalwebsites / download-example.php
Last active Feb 29, 2020
PHP download file script code example
View download-example.php
echo '
<a href="">PHP download file</a>';
finalwebsites / index.html
Last active Dec 29, 2019
Example code for the Ajax live search tutorial
View index.html
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ajax Live Search - DEMO</title>
<link rel="stylesheet" href="//">
<link href="starter-template.css" rel="stylesheet">
finalwebsites / redirect_to_checkout_after_login.php
Last active Oct 9, 2019
Redirect to the WooCommerce checkout page after login
View redirect_to_checkout_after_login.php
add_filter( 'woocommerce_registration_error_email_exists', function( $html ) {
$url = wc_get_page_permalink( 'myaccount' );
$url = add_query_arg( 'redirect_checkout', 1, $url );
$html = str_replace( 'Please log in', '<a href="'.$url.'"><strong>Please log in</strong></a>', $html );
return $html;
} );
add_filter( 'woocommerce_login_redirect', function( $redirect, $user ) {
if ( $_GET['redirect_checkout'] ) {
finalwebsites / add_wordpress_website_serverpilot.php
Last active Sep 15, 2019
Add a WordPress website via ServerPilot API and use WP-CLI for some modifications.
View add_wordpress_website_serverpilot.php
include_once 'ServerPilot.php';
include_once 'ServerPilotException.php';
function randomPassword($pw_length = 8) {
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < $pw_length; $i++) {
finalwebsites / conf.php
Last active Sep 23, 2019
Start your VPS on a different host node using PHP and the UpCloud API.
View conf.php
// Enter here your server UID and the login / password
$uid = 'xxx-xxx-xxx-xxx-xxx';
$host = ''.$uid;
$username = 'XXX';
$password = 'XXXXXXXX';
View post-ratings-plugin-stars-only.php
function showRating($id, $css_class = 'post-ratings') {
global $wpdb;
$path = plugins_url('wp-postratings/images/'.get_option('postratings_image'));
$rating = $wpdb->get_var("SELECT AVG(rating_rating) AS rating FROM $wpdb->ratings WHERE rating_postid = $id");
$i = 0;
$html = '
<span class="'.$css_class.'">';
if (!empty($rating)) {
while ($i > floor($rating)) {
You can’t perform that action at this time.