Skip to content

Instantly share code, notes, and snippets.

View yanknudtskov's full-sized avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
@yanknudtskov
yanknudtskov / woocommerce-shipmondo-track-and-trace.php
Created February 18, 2020 19:30
WooCommerce Shipmondo Track and Trace on Orders and Emails
<?php
/**
* Display track and trace if available
*/
add_filter( 'woocommerce_admin_order_preview_get_order_details', 'yanco_woocommerce_admin_order_preview_track_and_trace', 8, 2 );
function yanco_woocommerce_admin_order_preview_track_and_trace( $args, $order ) {
$order_id = $order->get_id();
$carrier = get_post_meta( $order_id, 'carrier', true );
@yanknudtskov
yanknudtskov / functions.php
Last active May 13, 2020 03:17
WooCommerce Subscriptions and LearnDash, based on the work of https://thomaslecoz.com/learndash-with-woocommerce-subscriptions/#code-update
<?php
add_action('cancelled_subscription', 'remove_course_access', 10, 2);
add_action('subscription_put_on-hold', 'remove_course_access', 10, 2);
add_action('subscription_expired', 'remove_course_access', 10, 2);
add_action('activated_subscription', 'give_course_access', 10, 2);
function send_receipt($order_id){
//if($new_status == 'processing' && $status != 'completed' || $new_status == 'completed' && $status == 'processing'){
if($status != 'processing' && $status != 'completed') {
@yanknudtskov
yanknudtskov / functions.php
Created February 10, 2020 07:38
Filter out products from search if they are hidden from catalogue as WooCommerce doesn't do this per default.
<?php
add_action( 'pre_get_posts', 'set_posts_per_page' );
function set_posts_per_page( $query ) {
if( !is_admin() ) {
if( is_search() ) {
$tax_query = (array) $query->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_visibility',
@yanknudtskov
yanknudtskov / functions.php
Created February 10, 2020 07:38
Filter out products from search if they are hidden from catalogue as WooCommerce doesn't do this per default.
<?php
add_action( 'pre_get_posts', 'set_posts_per_page' );
function set_posts_per_page( $query ) {
if( !is_admin() ) {
if( is_search() ) {
$tax_query = (array) $query->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_visibility',
@yanknudtskov
yanknudtskov / funtions.php
Created October 23, 2019 10:10
Disable repeat purchases of a WooCommerce Product based on product ID
<?php
/**
* Disables repeat purchase for the product
*
* @param bool $purchasable true if product can be purchased
* @param \WC_Product $product the WooCommerce product
* @return bool $purchasable the updated is_purchasable check
*/
function sv_disable_repeat_purchase( $purchasable, $product ) {
@yanknudtskov
yanknudtskov / functions.php
Created September 16, 2019 12:09
Process shortcodes in Gravity Forms field labels
<?php
/**
* Process Shortcodes in Gravity Forms field labels
*/
define( 'ACF_GRAVITY_FORM_ID', 1 ); // The ID of the form to process
add_filter( 'gform_pre_render_' . ACF_GRAVITY_FORM_ID, 'yanco_process_shortcodes_gravityforms_field_labels' );
function yanco_process_shortcodes_gravityforms_field_labels( $form ) {
@yanknudtskov
yanknudtskov / queries.sql
Last active August 28, 2019 12:25
Cleaning out WordPress Database in relation to very large comments table
DELETE FROM wp_postmeta
WHERE post_id IN (
SELECT ID from wp_posts WHERE post_title = 'sfn_followup_emails'
);
DELETE FROM wp_posts WHERE post_title = 'sfn_followup_emails';
DELETE FROM wp_postmeta
WHERE post_id IN (
SELECT ID from wp_posts WHERE post_title = 'wcs_report_update_cache' and post_status != 'pending'
@yanknudtskov
yanknudtskov / search-by-algolia-for-woocommerce.php
Created August 22, 2019 13:51 — forked from rayrutjes/search-by-algolia-for-woocommerce.php
This is a boilerplate for using Algolia in WooCommerce
<?php
/**
* @wordpress-plugin
* Plugin Name: Search by Algolia for WooCommerce - Instant & Relevant results
*/
/**
* If Algolia is not active, let users know.
@yanknudtskov
yanknudtskov / functions.php
Last active October 7, 2021 20:14
When PHPs upload limit is reached, the mailserver will reject the message using a HTTP Error 413 Request entity too large. This code for gravity forms fixes this by setting a fileupload limit, checking each forms attachements. If the limit is reached, the attachments are removed from the e-mail (they are still on the entry in Gravity Form) and t…
<?php
// define( 'ONE_MB', 1024 ); // 1 * 1024
// define( 'TWENTYFIVE_MB', 26214400 ); // 25 * 1024
// define( 'TWENTYFOUR_MB', 25165824 ); // 24 * 1025
define( 'LARGE_NOTIFICATIONS_ATTACHMENT_LIMIT_IN_BYTES', 25165824 ); // 24 * 1025 = 24MB
add_filter( 'gform_notification', 'yanco_filter_large_notification_attachments', 10, 3 );
function yanco_filter_large_notification_attachments( $notification, $form, $entry ) {
@yanknudtskov
yanknudtskov / functions.php
Created August 14, 2019 09:26
This file contains a bunch of helper functions that handle add caching to core WordPress functions.
<?php
/**
* This file contains a bunch of helper functions that handle add caching to core WordPress functions.
*/
/**
* Cached version of get_category_by_slug.
*
* @param string $slug Category slug
* @return object|null|bool Term Row from database. Will return null if $slug doesn't match a term. If taxonomy does not exist then false will be returned.