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 May 2, 2018 11:37
How to remove decimal points for products in #woocommerce where they end on 0 (zero)
<?php
/*
* Trim zeros in price decimals
*/
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
@yanknudtskov
yanknudtskov / functions.php
Created August 26, 2018 16:36
Allow SVG upload in WordPress
<?php
/**
* Allow SVG Upload
*/
add_filter('upload_mimes', 'yanco_mime_types');
function yanco_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
@yanknudtskov
yanknudtskov / functions.php
Created November 13, 2018 16:41
Create a WordPress Admin user through functions.php - Remember to remove the codesnippet after the user has been created.
<?php
add_action( 'init', function () {
$username = 'USER NAME HERE';
$password = 'PASSWORD HERE';
$email_address = 'EMAIL HERE';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
@yanknudtskov
yanknudtskov / .htaccess
Created December 4, 2018 07:56
Noindex PDF files in .htaccess
#Noindex PDF
<Files ~ "\.pdf$">
Header set X-Robots-Tag "noindex"
</Files>
#Noindex PDF
@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
@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 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 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: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 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';
}