Skip to content

Instantly share code, notes, and snippets.

View rwsite's full-sized avatar
✌️

Aleksei Tikhomirov rwsite

✌️
View GitHub Profile
@rwsite
rwsite / woo.php
Created June 5, 2018 13:06
Показ ID катгорий товаров в WooCommerce
/**
* WooCommerce: Показ ID категорий
*/
// Добавляем столбец ID
function woo_cat_id_columns($columns){
$columns = array('tag_ID' => __('ID', 'rw-addon'))+ $columns;
return $columns;
}
add_filter("manage_edit-product_cat_columns", "woo_cat_id_columns");
// Отображаем столбец 'tag_ID'
@rwsite
rwsite / yoastSeo.js
Created August 31, 2018 01:01
Adding Content from custom fields to Yoast SEO Analysis Using YoastJS
console.log('script ready');
(function($) {
var MyYoastPlugin = function()
{
YoastSEO.app.registerPlugin('myYoastPlugin', {status: 'loading'});
this.getData();
@rwsite
rwsite / dublicate_posts.php
Created January 21, 2019 19:51
Dublicate posts worpress
<?php
/*
* Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
*/
function rd_duplicate_post_as_draft(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
wp_die('No post to duplicate has been supplied!');
}
@rwsite
rwsite / abstract_factory.php
Created March 21, 2021 14:58
Abstract Factory example in PHP
<?php
/* Abstract Factory in PHP */
interface FactoryOS
{
public static function createMenu() : Menu;
public static function createButton() : Button;
}
@rwsite
rwsite / wc-skeleton-shipping-method-example.php
Created September 2, 2021 09:26 — forked from woogists/wc-skeleton-shipping-method-example.php
[Shipping Method API] WooCommerce skeleton shipping method plugin code example.
<?php
/*
Plugin Name: Your Shipping plugin
Plugin URI: https://woocommerce.com/
Description: Your shipping method plugin
Version: 1.0.0
Author: WooThemes
Author URI: https://woocommerce.com/
*/
@rwsite
rwsite / woo-to-iiko.php
Last active October 10, 2021 16:55
woo2iiko default value for teminal's select
add_filter('iiko_checkout_fields', function ($fields){
$fields['delivery_terminal']['default'] = '';
$fields['delivery_terminal']['options'] = [''=>''] + $fields['delivery_terminal']['options'];
return $fields;
}, 10, 1 );
add_action( 'woocommerce_after_checkout_validation', function ($data, \WP_Error $errors) {
if(isset($data['billing_delivery_terminal']) && empty($data['billing_delivery_terminal'])){
$errors->add('iiko_terminal', __('Please select the terminal', 'iiko'));
}
add_filter('wc_iiko_product', function (ProductArg $data, \iiko\classes\Product $iiko_product ){
if(!empty($iiko_product->tags) && false !== strpos($iiko_product->tags, 'Избранные' )) {
$data->featured = true;
}
return $data;
}, 10, 2 );
@rwsite
rwsite / class-wp-ajax-example.php
Last active December 21, 2022 22:48
WP AJAX Example class
<?php
// WP AJAX example
class WP_AJAX_Example{
/**
* Add WP actions. Must be called only once.
* @return void
*/
public function add_actions(){
@rwsite
rwsite / wp-theme.php
Created December 28, 2022 01:46
Wordpress Autoload classes
/**
* WordPress Autoload classes.
*/
spl_autoload_register( function ( $full_class_name ) { //phpcs:ignore PEAR.Functions.FunctionCallSignature
if ( strpos( $full_class_name, __NAMESPACE__ ) !== 0 ) { // . '\Core'
return; // Not in the plugin namespace, don't check.
}
$full_class_name = strtolower( str_replace( '_', '-', $full_class_name ) );
$class_parts = explode( '\\', $full_class_name );
unset( $class_parts[0] ); // Unset the __NAMESPACE__.
@rwsite
rwsite / woo2iiko-functions
Created September 18, 2023 12:31
remove DeliveryDurationInMinutes
add_action('woocommerce_before_thankyou', function ($wc_order_id){
$wc_order = wc_get_order($wc_order_id);
if (empty($wc_order) || $wc_order->has_status('failed')) {
return;
}
$wc_order->update_meta_data('deliveryDurationInMinutes', '');
$wc_order->save_meta_data();
}, 5);