Skip to content

Instantly share code, notes, and snippets.

View mrpsiho's full-sized avatar

Vitalii Kiiko mrpsiho

View GitHub Profile
add_rewrite_rule('sushi-cats/([^/]*)/metro/([^/]*)/?$','index.php?product_cat=$matches[1]&metro=$matches[2]','top');
add_rewrite_rule('sushi-cats/(sushi|roll|set)/metro/([^/]*)/?$','index.php?product_cat=$matches[1]&metro=$matches[2]','top');
function uni_add_rewrite_rules() {
add_rewrite_rule('sushi-cats/([^/]*)/metro/([^/]*)/?$','index.php?product_cat=$matches[1]&metro=$matches[2]','top');
add_rewrite_rule('sushi-cats/(sushi|roll|set)/metro/([^/]*)/?$','index.php?product_cat=$matches[1]&metro=$matches[2]','top');
}
add_action( 'init', 'uni_add_rewrite_rules' );
function uni_add_rewrite_tag() {
add_rewrite_tag('%metro%', '([^&]+)');
}
add_action('init', 'uni_add_rewrite_tag', 10, 0);
function uni_add_query_vars( $public_query_vars ) {
$public_query_vars[] .= 'metro';
return $public_query_vars;
}
add_filter('query_vars', 'uni_add_query_vars');
<?php
/*
* Template Name: Contact Form
*/
get_header(); ?>
<h1>Контактна форма</h1>
<?php if ( 'success' == get_query_var( 'form' ) ): ?>
<div class="message">
Ваше повідомлення надіслано!
@mrpsiho
mrpsiho / class.php
Created November 16, 2017 08:41 — forked from hlashbrooke/class.php
A complete, versatile options page class for any WordPress plugin
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class WordPress_Plugin_Template_Settings {
private $dir;
private $file;
private $assets_dir;
private $assets_url;
private $settings_base;
@mrpsiho
mrpsiho / gist:ddd09acf639ab486ca368461c80d68ff
Last active March 5, 2018 17:59
ShipperHQ for WC (ver. 1.3.2 https://wordpress.org/plugins/woo-shipperhq/). Replace 'populateAttributes' method with one mentioned below in order to hook in and read cart item dimensions instead of static ones added to a product. It makes ShipperHQ compatible with UniCPO 4 plugin.
/**
* Reads attributes from the item
*
* @param $productData
* @param $product
* @return array
*/
protected function populateAttributes($productData, $product)
{
$attributes = [];
@mrpsiho
mrpsiho / gist:12cadb35d84d21d844d10385f1c9f70d
Last active October 2, 2018 13:27
Exclude/change attributtes for billing/shipping fields on the WooCommerce checkout page
add_action( 'wp', 'uni_checkout_under_certain_circumstances' );
function uni_checkout_under_certain_circumstances() {
if ( function_exists( 'is_checkout' ) && ( is_checkout() || is_ajax() ) ) {
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
// the following line disables "notes" field
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
// an example of unsetting checkout fields
add_filter( 'woocommerce_checkout_fields', 'uni_unset_billing_checkout_fields', 10, 1 );
// an example of modifying atributtes of checkout fields
@mrpsiho
mrpsiho / gist:73357ad1409a2b345dc865296f8279f6
Created January 29, 2019 08:42
Fixing background color selection in Flatsome theme
const flickty = jQuery('.woocommerce-product-gallery__wrapper').data('flickity');
if (typeof flickty !== 'undefined' && flickty.slides.length > 1) {
flickty.destroy();
jQuery('.woocommerce-product-gallery__wrapper').flickity({
draggable: false
});
}
@mrpsiho
mrpsiho / functions.php
Created February 6, 2021 20:18
Pairing custom meta field with NOV in Uni CPO
add_action( 'woocommerce_product_options_pricing', 'uni_display_fields' );
add_action( 'woocommerce_process_product_meta', 'uni_save_fields' );
function uni_display_fields() {
woocommerce_wp_text_input(
array(
'id' => 'uni_paired_meta',
'label' => 'Meta field paired with NOV',
'description' => 'This value will be used instead of {uni_nov_cpo_paired_meta}',
)