Skip to content

Instantly share code, notes, and snippets.

View danmeade's full-sized avatar

Dan Meade danmeade

View GitHub Profile
@yanknudtskov
yanknudtskov / functions.php
Created November 20, 2020 11:37
Add a WooCommerce Checkbox at Checkout to accept privacy policy.
<?php
/**
* Add privacy policy tick box at checkout
*/
add_action( 'woocommerce_review_order_before_submit', 'yanco_add_checkout_privacy_policy', 9 );
function yanco_add_checkout_privacy_policy() {
woocommerce_form_field( 'privacy_policy', array(
'type' => 'checkbox',
'class' => array('form-row privacy'),
@yanknudtskov
yanknudtskov / functions.php
Created November 4, 2020 12:00
WooCommerce Subscriptions: Also send Subscription Cancelled email to customer
<?php
add_action('woocommerce_subscription_status_pending-cancel', 'yanco_woocommerce_subscription_status_pending_cancel', 10, 3 );
function yanco_woocommerce_subscription_status_pending_cancel( $subscription ) {
$customer_email = $subscription->get_billing_email();
$wc_emails = WC()->mailer()->get_emails();
$admin_email = $wc_emails['WCS_Email_Cancelled_Subscription']->recipient;
$wc_emails['WCS_Email_Cancelled_Subscription']->trigger( $subscription );
@yanknudtskov
yanknudtskov / functions.php
Created September 8, 2020 09:44
Adjust Facebook for WooCommerce Feed Regeneration Interval
<?php
/*
* Adjust the interval that the feed file is generated.
*/
add_filter( 'wc_facebook_feed_generation_interval', 'yanco_wc_facebook_feed_generation_interval', 10, 1 );
function yanco_wc_facebook_feed_generation_interval( $interval ) {
return 60 * 30;
}
@yanknudtskov
yanknudtskov / functions.php
Created June 25, 2020 14:55
Remove ACF validation for administrators
<?php
// Disable Ready Only for Administrators
// add_filter( 'acf/load_field', 'yanco_acf_disable_read_only', 10000 );
function yanco_acf_disable_read_only( $field ) {
// Applies to administrators
if( is_admin() && get_post_type() == 'afrapportering' ) {
global $pagenow;
@yanknudtskov
yanknudtskov / functions.php
Created May 19, 2020 14:50
Change the label for the ACF Post Title field when used in acf_form( $args )
<?php
add_filter( 'enter_title_here', 'yanco_change_title_text' );
function yanco_change_title_text( $title ){
$screen = get_current_screen();
if ( 'leverandor' == $screen->post_type ) {
$title = 'Virksomhedsnavn';
}
@yanknudtskov
yanknudtskov / functions.php
Last active October 7, 2021 20:11
How to defer parsing of scripts loaded with WordPress wp_enqueue_script
<?php
function yanco_defer_script_loader_tag( $tag, $handle, $src ) {
$defer = array(
'magnific-popup',
'cycle',
'script'
);
if ( in_array( $handle, $defer ) ) {
return '<script src="' . $src . '" defer="defer" type="text/javascript"></script>' . "\n";
@yanknudtskov
yanknudtskov / functions.php
Created March 12, 2020 12:32
WooCommerce Products per page dropdown
<?php
add_action( 'woocommerce_before_shop_loop', 'yanco_products_per_page_selectbox', 25 );
function yanco_products_per_page_selectbox() {
$html = '';
$style = 'font-size: 16px;
font-weight: 300;
font-family: inherit;
letter-spacing: 1px;
@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 / function.php
Created August 6, 2019 15:15
Adding custom fields to woocommerce products
<?php
// From https://remicorson.com/mastering-woocommerce-products-custom-fields/
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
@yanknudtskov
yanknudtskov / functions.php
Last active June 20, 2023 19:30
WooCommerce Subscriptions check if the current user has an active subscription
<?php
function yanco_has_active_subscription( $user_id = '' ) {
if( function_exists( 'wcs_user_has_subscription' ) ) {
// When a $user_id is not specified, get the current user Id
if( '' == $user_id && is_user_logged_in() ) {
$user_id = get_current_user_id();
}
// User not logged in we return false