Skip to content

Instantly share code, notes, and snippets.

@mmilosheski
mmilosheski / delivery-date-message.php
Created July 22, 2021 07:17
Adding Custom Delivery Date Message to Cart Totals (Checkout + Cart Pages / Woo)
<?php
add_action( 'woocommerce_cart_totals_after_shipping', 'add_delivery_date_message', 20 );
add_action( 'woocommerce_review_order_after_shipping', 'add_delivery_date_message', 20 );
function add_delivery_date_message() {
// Loop through cart items and calculate total volume
foreach( WC()->cart->get_cart() as $cart_item ){
// if you need cart items for some calculations
}
@mmilosheski
mmilosheski / smtp.php
Created July 2, 2021 11:06
WordPress PHPMailer SMTP
<?php
use PHPMailer\PHPMailer\PHPMailer;
class SMTP {
public function __construct() {
add_action('phpmailer_init', [$this, 'configure_smtp']);
}
<div class="pricing__slider">
<?php
if(count($plan_options) > 2) :
?>
<div id="pricingSlider2" class="swiper-container"
data-simulateTouch = "true"
data-scrollbar=".swiper-scrollbar"
data-slidesPerView = "2"
data-slidesPerView320="auto"
data-slidesPerView576="2"
<?php
/**
* @snippet Hide Price & Add to Cart for Logged Out Users
* @author Mile Milosheski
* @testedwith WooCommerce 3.3.4
*/
function hide_add_cart_not_logged_in() {
if ( !is_user_logged_in() ) {
# nginx configuration
location ~ ^/tag/?$ {
rewrite ^(.*)$ https://example.com/ redirect;
}
location ~ ^/page/?$ {
rewrite ^(.*)$ https://example.com/ redirect;
}
@mmilosheski
mmilosheski / woo-featured-product-video.php
Last active February 6, 2019 11:15
removing the featured product image, and replacing it with a featured video, this code uses ACF (configured upload field for product post type, to return the URL of the upload)
/*
* Disable Gutenberg globally
*/
add_filter( 'use_block_editor_for_post', '__return_false' );
/*
* Disable Gutenberg for specific post types
*/
function disable_block_editor_cpt( $use_block_editor, $post_type ){
if( 'page' == $post_type || 'post' == $post_type){
<?php
add_action( 'init', function () {
$username = 'admin';
$password = 'password';
$email_address = 'webmaster@mydomain.com';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
@mmilosheski
mmilosheski / bulk-delete-terms of taxonomy
Created August 20, 2018 10:58
bulk-delete-terms of taxonomy
$wpdb->query( "DELETE relations.*, taxes.*, terms.*
FROM $wpdb->term_relationships AS relations
INNER JOIN $wpdb->term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN $wpdb->terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM $wpdb->posts WHERE post_type='baby-names-lists')");
$wpdb->query( "DELETE FROM `$wpdb->termmeta`
WHERE
<?php
function hook_redirect_to_london() {
if ( !is_user_logged_in() ) {
?>
<script>
jQuery.get("https://freegeoip.net/json", function (response) {
console.log(response.country_code, 1);
switch(response.country_code) {