Skip to content

Instantly share code, notes, and snippets.

@slavapas
slavapas / FUNCTIONS.PHP with DEFINE VARIALBLES
Created January 14, 2021 18:59
standart functions.php with varialbes PATH
<?php
// define constant
define('PS_THEME_ROOT', get_template_directory_uri());
define('PS_CSS_DIR', PS_THEME_ROOT . '/assets/css');
define('PS_JS_DIR', PS_THEME_ROOT . '/assets/js');
define('PS_IMG_DIR', PS_THEME_ROOT . '/assets/img');
// правильный способ подключить стили и скрипты
add_action('wp_enqueue_scripts', 'theme_name_scripts');
/* Automatically set the image Title, Alt-Text, Caption & Description upon upload
--------------------------------------------------------------------------------------*/
add_action( 'add_attachment', 'my_set_image_meta_upon_image_upload' );
function my_set_image_meta_upon_image_upload( $post_ID ) {
// Check if uploaded file is an image, else do nothing
if ( wp_attachment_is_image( $post_ID ) ) {
$my_image_title = get_post( $post_ID )->post_title;
define('PS_THEME_ROOT', get_template_directory_uri());
define('PS_CSS_DIR', PS_THEME_ROOT . '/assets/css');
define('PS_JS_DIR', PS_THEME_ROOT . '/assets/js');
define('PS_IMG_DIR', PS_THEME_ROOT . '/assets/img');
function ps_my_styles_and_scripts(){
// styles
wp_equeue_style('my_style', PS_CSS_DIR . '/style.css');
wp_equeue_script('my_default_style', get_stylesheet_directory_uri());
@slavapas
slavapas / Plus and Minus signs on Single Product
Created May 15, 2021 08:21
Plus and Minus signs on Single Product quantity
/**
* Plus and Minus signs on Single Product
*/
add_action('woocommerce_after_add_to_cart_quantity', 'ts_quantity_plus_sign');
function ts_quantity_plus_sign() {
echo '<button type="button" class="plus" >+</button>';
}
add_action('woocommerce_before_add_to_cart_quantity', 'ts_quantity_minus_sign');
@slavapas
slavapas / WooCommerce - Change the content of Single Product Page - Price Variation content
Last active May 25, 2021 11:54
WooCommerce - Change the content of Single Product Page - Price Variation content
// Change the content of Price Variation content
add_filter('woocommerce_available_variation', 'variation_price_custom_suffix', 10, 3);
function variation_price_custom_suffix($variation_data, $product, $variation) {
$variation_data['price_html'] .= ' <span class="price-suffix">' . __("each", "woocommerce") . '</span>';
$var1 = $variation_data['availability_html'];
var_dump($var1);
foreach ($var1 as $var) {
var_dump($var);
}
// var_dump($variation_data);
@slavapas
slavapas / gist:b7e6cf8419a8cc7ada0a78b58064958b
Created May 25, 2021 12:00
WooCommerce - Add additional content bellow the Product Title on the Cart Page
// PHP
function alt_message() {
return '<p class="backorder_notification backorder_notification_custom">Please allow 20 days for delivery of this item</p>';
}
function backorder_text($availability) {
$altmessage = alt_message();
foreach ($availability as $i) {
$availability = str_replace('Available on backorder', $altmessage, $availability);
}
@slavapas
slavapas / gist:22f2e3019da2e690f8990fb583f75c56
Created May 25, 2021 12:14
WooCommerce - Get quantity of the active selected product variation in WooCommerce
add_action('woocommerce_before_add_to_cart_button', 'get_selected_variation_stock', 11, 0);
function get_selected_variation_stock() {
global $product, $wpdb;
// HERE set your custom message
$message_outofstock = __('My custom "out of stock" message');
// Get the visible product variations stock quantity
$variations_data = array();
$child_ids = $product->get_visible_children();
@slavapas
slavapas / .. MediaCreationTool.bat ..md
Created October 16, 2021 04:15 — forked from AveYo/.. MediaCreationTool.bat ..md
Universal MediaCreationTool wrapper for all MCT Windows 10 versions from 1507 to 21H1 with business (Enterprise) edition support

We did it! We broke gist.github.com ;) So head over to the new home! Thank you all!

Not just an Universal MediaCreationTool wrapper script with ingenious support for business editions,
Preview
A powerful yet simple windows 10 / 11 deployment automation tool as well!

configure via set vars, commandline parameters or rename script like iso 21H2 Pro MediaCreationTool.bat
recommended windows setup options with the least amount of issues on upgrades set via auto.cmd
awesome dialogs with keyboard focus to pick target version and preset action

@slavapas
slavapas / functons.php
Created January 22, 2022 18:38
Contact Form 7 : How to enable shortcodes in Form and Mail Template
// Contact Form 7 : How to enable shortcodes in Form and Mail Template
function my_special_mail_tag( $output, $name, $html ) {
if ( 'myshortcode' == $name )
$output = do_shortcode( "[$name]" );
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );
@slavapas
slavapas / functions.php
Last active January 25, 2022 11:37
Hide shipping rates when free shipping is available.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {