// ========================================================================= // ADD EXTRA FEE TO SPECIFIC SHIPPING METHOD // ========================================================================= add_action('woocommerce_cart_calculate_fees', 'add_handling_fee_for_specific_shipping_method', 10, 1); function add_handling_fee_for_specific_shipping_method($cart) { if (is_admin() && !defined('DOING_AJAX')) return; $chosen_methods = WC()->session->get('chosen_shipping_methods'); $chosen_shipping = $chosen_methods[0]; if ($chosen_shipping === 'flat_rate:5') { $fee = 500; // Kezelési költség mértéke $cart->add_fee(__('Kezelési költség postai kézbesítés esetén', 'woocommerce'), $fee); } }
Free
Add notification to specific shipping method in WooComerce
// ========================================================================= // ADD NOTIFICATION TO SPECIFIC SHIPPING METHOD // ========================================================================= add_action('woocommerce_review_order_before_payment', function () { ?> <div id="mpl-warning" style="display:none;"> Figyelem! Amennyiben postával rendelne, 500 Ft kezelési költséget számítunk fel és a kiszállítási időt csak 20 napon belül tudjuk vállalni. </div> <script type="text/javascript"> jQuery(function($) { function updateHelloWorldVisibility() { var chosen_shipping = $('input[name^="shipping_method"]:checked').val(); if (chosen_shipping === 'flat_rate:5') { $("#mpl-warning").show(); } else { $("#mpl-warning").hide(); } } // Frissítjük a "Hello World" szöveg láthatóságát szállítási mód változásakor $(document.body).on('change', 'input[name^="shipping_method"]', updateHelloWorldVisibility); // Az oldal betöltésekor is ellenőrizzük a szállítási módot updateHelloWorldVisibility(); }); </script> <?php }, 10, 2);
How to use wp_kses in ACF?
functions.php
// ============================================================= // ALLOWED HTML IN ACF // ============================================================= function wpflames_allowed_html() { return array( 'a' => array( 'href' => array(), 'title' => array(), 'class' => array(), ), 'br' => array(), 'em' => array(), 'strong' => array(), ); }
<?php echo wp_kses(get_field('text'), wpflames_allowed_html()); ?>
Delete all WordPress posts from phpMyAdmin
DELETE FROM wp_posts WHERE post_type = 'post';
How to use Mailgun as SMTP without plugin
If You want to replace WP Mail SMTP plugin use this snippet.
Add discount checkbox field to WooCommerce checkout, save meta data, display in admin and in email
Add extra fee to COD payment gateway
Prettier doesn’t format the code
- Go to Settings and search for formatter.
- Set the default formatter to Prettier
Use SVG Icons
.icon { display: inline-block; min-width: 5px; min-height: 5px; background-position: center; background-size: contain; background-repeat: no-repeat; } .icon.icon-print { background-image: url('../images/icons/print.svg'); min-width: 20px; min-height: 20px; }
<i class="icon icon-print"></i>
Insert page in to another page
// ========================================================================= // INSERT PAGE TO ANOTHER PAGE // ========================================================================= function page_partners() { $args = new WP_Query("page_id=285"); while($args->have_posts()) : $args->the_post(); the_content(); endwhile; }
Tab Panel with JavaScript
ACF Option Pages with Repeater Group and File
SCSS
Hamburger menu for WordPress custom theme
Enqueue Scripts Asynchronously in WordPress
If you regularly build sites with WordPress and test them against Google PageSpeed Insights, you’ll probably have encountered it complaining about async and defer on your scripts.
v@wordpress/scripts
The official WordPress JavaScript tool
npm install @wordpress/scripts --save-dev
package.json
npm install
Changing file entry and output of build scripts
Watch and compile
npm run start
Import JavaScript
Automatically set image Alt-Text during upload in WordPress
File Renaming on Upload without plugin in WordPress
Rename files during upload within WordPress
How to remove accents from uploaded filenames
Remove Genesis Admin Warnings
If You have a Genesis Pro Lifetime subscription, there’s an annoying notification in the plugins section. Just paste the following snippet in the functions.php to remove the warning messages.
Display Option Pages for Post Object, Repeater
<?php if( have_rows('your_repeater_field', 'option') ): ?> <?php while ( have_rows('your_repeater_field', 'option') ) : the_row(); ?> <?php $post_object = get_sub_field('your_post_object', 'option'); ?> <?php if( $post_object ): ?> <?php $post = $post_object; setup_postdata( $post ); $title = get_the_title( $post_object->ID); ?> <h4><?= $title ?></h4> <?php wp_reset_postdata(); ?> <?php endif; ?> <?php endwhile; ?> <?php endif; ?>
ACF Query Upcoming and Past Events
events-query.php
upcoming.php
past.php