Skip to content

Instantly share code, notes, and snippets.

View RickardAhlstedt's full-sized avatar

Rickard Ahlstedt RickardAhlstedt

View GitHub Profile
@RickardAhlstedt
RickardAhlstedt / functions.php
Created February 2, 2023 08:30
Polylang - show review count in tabs on other languages and show rating on translated products.
<?php
add_filter( 'woocommerce_product_tabs', 'ao_tabs' );
function ao_tabs( $tabs ) {
foreach( $tabs as $sKey => $aTab ) {
if( $aTab['callback'] == 'comments_template' ) {
if( $sTransTitle = get_transient( 'product_' . get_queried_object_id( ) . '_review_count' ) ) {
$tabs[$sKey]['title'] = $sTitle;
}
@RickardAhlstedt
RickardAhlstedt / fix.sh
Created January 27, 2023 03:09
When brew update goes wrong and valet & php refuses to work
brew unlink php && brew link php
brew services restart --all
composer global update
valet install
@RickardAhlstedt
RickardAhlstedt / class-wup-track-shipment.php
Created December 8, 2022 09:54
Call to a member function get_shipping_country() on string in /wp-content/plugins/woo-pacsoft-unifaun/src/class-wup-track-shipment.php:33
<?php
...
// Add the following code to line 32 in file /woo-pacsoft-unifaun/src/class-wup-track-shipment.php
// This will ensure that the returned object is actually an object, and not a string that seems to be returned when using wc_get_order
$order = new \WC_Order( $order );
...
?>
@RickardAhlstedt
RickardAhlstedt / scgode.ino
Last active August 4, 2022 09:35
Simplified G-Code parser for Arduino UNO
// https://wokwi.com/projects/339048333809025620
void setup() {
Serial.begin(9600);
}
int linearGuideLength = 100;
// A variable to determine if the system can receive configuration or not.
bool systemBusy = false;
<?php
/**
* ContainerBridge.php
*
* Copyright © 2005-2006, FileMaker, Inc. All rights reserved.
* NOTE: Use of this source code is subject to the terms of the FileMaker
* Software License which accompanies the code. Your use of this source code
* signifies your agreement to such license terms and conditions. Except as
* expressly granted in the Software License, no other copyright, patent, or
* other intellectual property license or right is granted, either expressly or
@RickardAhlstedt
RickardAhlstedt / #1 Person.php
Last active November 10, 2020 23:08
Single Inheritance-example
<?php
/* Dependencies.. */
class Person {
public $sName;
protected $iAge;
private $mPhone;
public function talk() { ... }
@RickardAhlstedt
RickardAhlstedt / retry.php
Created May 5, 2020 12:10 — forked from HonzaMac/retry.php
Retry any function in php
<?php
if (!function_exists('retry')) {
/**
* Retries callable
*
* Could be specified how many times, default is 1 times.
*
* @param callable $what
* @param int $retry how many time should it be retried, default is 1
* @return mixed
@RickardAhlstedt
RickardAhlstedt / functions.php
Created April 7, 2020 09:39 — forked from maddisondesigns/functions.php
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty
@RickardAhlstedt
RickardAhlstedt / install_composer.sh
Created January 18, 2020 22:31
Install composer on mac os x
#!/bin/sh
mkdir tmp
cd tmp
curl -sS https://getcomposer.org/installer | php
copy composer.phar /usr/local/bin
echo alias composer="php /usr/local/bin/composer.phar" > ~/.bash_profile
source ~/.bash_profile
cd ..