Skip to content

Instantly share code, notes, and snippets.

View maxkostinevich's full-sized avatar
🚧
Work in progress

Max Kostinevich maxkostinevich

🚧
Work in progress
View GitHub Profile
@maxkostinevich
maxkostinevich / script.rb
Created June 7, 2018 07:17
Shopify Script #1 - Spend $A, get B% off, spend $C get D% off, spend $E get F% off
# Spend $A, get B% off, spend $C get D% off, spend $E get F% off
# Custom Message
CHECKOUT_MESSAGE = "Special discount"
# Discount rules
# ORDER MINIMUM IN DOLLARS => DISCOUNT VALUE (%)
DISCOUNT_RULES = {
50 => 5,
100 => 10,
@maxkostinevich
maxkostinevich / AppServiceProvider.php
Last active April 15, 2020 19:06
Laravel Force SSL
<?php
// Just add the following code to boot() method:
// \URL::forceSchema('https'); // for Laravel 5.3
// \URL::forceScheme('https'); // for Laravel 5.4
// ...
class AppServiceProvider extends ServiceProvider
{
@maxkostinevich
maxkostinevich / php-fpm-restart.sh
Last active February 17, 2022 17:40
Cloudways PHP-FPM restart via API
# Restart PHP-FPM on CloudWays via API
# Replace YOUR_NAME%40DOMAIN.COM with your email (URL-encoded), YOUR_API_KEY with your Cloudways API key and SERVER_ID with id of your server
# If you want to use it with DeployBot just add the following commands to the "Run commands after new version becomes active" section.
# Do auth and receive access_token
cloudways_token=$(curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'email=YOUR_NAME%40DOMAIN.COM&api_key=YOUR_API_KEY' 'https://api.cloudways.com/api/v1/oauth/access_token' | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])")
# Restart PHP-FPM
curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' --header "Authorization: Bearer ${cloudways_token}" -d 'server_id=SERVER_ID&service=php7.0-fpm&state=restart' 'https://api.cloudways.com/api/v1/service/state'
@maxkostinevich
maxkostinevich / script.js
Created November 17, 2016 09:04
JS Selected Text
$('.element').on('mouseup', function(event){
var selection;
if (window.getSelection) {
selection = window.getSelection();
} else if (document.selection) {
selection = document.selection.createRange();
}
selection.toString() !== '' && alert('"' + selection.toString() + '" was selected at ' + event.pageX + '/' + event.pageY);
@maxkostinevich
maxkostinevich / functions.php
Created September 19, 2016 03:24
WooCommerce - How to hide product price and attributes for non-authorized users
<?php
// Hide WooCommerce product price, attributes and variations for non-logged-in users
function my_theme_hide_price_not_authorized() {
if ( !is_user_logged_in() ) {
// Hide price
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Hide variations
add_filter( 'woocommerce_variation_is_active', 'my_theme_disable_variation', 10, 2 );
// Hide Add-to-cart button
@maxkostinevich
maxkostinevich / functions.php
Last active July 16, 2020 21:35
WooCommerce - How to change available package rates depending on cart total
<?php
// Change available package rates depending on cart total
function shipping_method_on_cart_total( $rates, $package ) {
$cart_total = WC()->cart->total;
$condition_price = 1000.00;
if( $cart_total > $condition_price ) {
unset( $rates['free_shipping'] ); // Remove free shipping
}
@maxkostinevich
maxkostinevich / functions.php
Last active March 12, 2018 19:57
WooCommerce - How to change available payment methods depending on cart total
<?php
// Change available payment methods depending on cart total
function payment_gateway_disable_payment_method( $available_gateways ) {
$cart_total = WC()->cart->total;
$condition_price = 1000.00;
if ( isset($available_gateways['cod']) && ($cart_total > $condition_price) ) {
unset( $available_gateways['cod'] ); // Disable "Cash on Delivery" payment method
}
@maxkostinevich
maxkostinevich / style.css
Created July 31, 2016 11:25
Fix navbar in-page anchor jumping
*[id]:before {
display: block;
content: " ";
margin-top: -75px;
height: 75px;
visibility: hidden;
}
@maxkostinevich
maxkostinevich / invoice.js
Last active November 13, 2023 21:02
PDFMake.js - Invoice Markup
// Invoice markup
// Author: Max Kostinevich
// BETA (no styles)
// http://pdfmake.org/playground.html
// playground requires you to assign document definition to a variable called dd
// CodeSandbox Example: https://codesandbox.io/s/pdfmake-invoice-oj81y
var dd = {
@maxkostinevich
maxkostinevich / new-site.php
Created May 2, 2016 00:14
WP Multisite create new site (example)
<?php
# Load WordPress barebones
define( 'WP_USE_THEMES', false );
require( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
# Multisite domain
$main_site = 'example.com';
# Type of Multisite
$subdomain_install = false;