Skip to content

Instantly share code, notes, and snippets.

View PechenkiUA's full-sized avatar
💭
On vacation

Pechenki PechenkiUA

💭
On vacation
View GitHub Profile
@PechenkiUA
PechenkiUA / functions.php
Created January 13, 2021 17:47
add field settings wp
<?php
add_action( 'admin_init', 'wpse_57647_register_settings' );
/*
* Register settings
*/
function wpse_57647_register_settings()
{
register_setting(
'general',
@PechenkiUA
PechenkiUA / common.js
Last active January 26, 2021 06:52
create html in js vanil
element = document.createElement('ul');
li = document.createElement("li")
liText = document.createTextNode('text')
li.appendChild(liText)
element.appendChild(li)
listresult.append(element)
/*
@PechenkiUA
PechenkiUA / outputCsv.php
Last active January 28, 2021 12:48
array to output Csv
public function outputCsv($fileName, $assocDataArray,$delimiter=';')
{
ob_clean();
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=' . $fileName);
if(isset($assocDataArray['0'])){
@PechenkiUA
PechenkiUA / csv _to_array.php
Created January 28, 2021 13:26
csv_to_array php
function csv_to_array($filename='', $delimiter=';'){
if(!file_exists($filename) || !is_readable($filename))
return FALSE;
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
{
@PechenkiUA
PechenkiUA / addForeignKey.php
Last active January 29, 2021 20:16
$this->addForeignKey yii2
<?php
// Добавляем foreign key
// Добавляем foreign key
$this->addForeignKey(
'FK_organization_id', // это "условное имя" ключа
'organization_sub', // это название текущей таблицы
'organization_id', // это имя поля в текущей таблице, которое будет ключом
'organization', // это имя таблицы, с которой хотим связаться
'id', // это поле таблицы, с которым хотим связаться
'CASCADE', // что делать при удалении сущности, на которую ссылаемся
@PechenkiUA
PechenkiUA / add-to-image.php
Last active February 10, 2021 21:10
add to image is galery product
<?php
add_action( 'woocommerce_before_shop_loop_item_title', function(){
if (is_user_logged_in()) {
global $product;
$attachment_ids = $product->get_gallery_image_ids();
$attr = ['class'=>'to-image'];
echo wp_get_attachment_image(reset($attachment_ids), 'shop_catalog',false, $attr);
}
@PechenkiUA
PechenkiUA / DateTimeFormat.php
Last active February 17, 2021 10:10
Date time Behavion yii2 to datepicker
<?php
namespace common\behaviors;
use yii\base\Behavior;
use yii\base\InvalidConfigException;
use yii\db\ActiveRecord;
use yii\base\Event;
@PechenkiUA
PechenkiUA / js.js
Created February 20, 2021 14:41
Блок в поле видимости
$(document).ready(function() {
function scrollTracking(){
var wt = $(window).scrollTop();
var wh = $(window).height();
var et = $('#activex').offset().top - 200;
var eh = $('#active').outerHeight();
if (wt + wh >= et && wt + wh - eh * 2 <= et + (wh - eh)){
@PechenkiUA
PechenkiUA / .htaccess
Created February 26, 2021 10:30
(multipart/form-data content
<If "%{REQUEST_URI} =~ /url/">
SetEnvIf Content-Type ^(multipart/form-data)(.*) NEW_CONTENT_TYPE=multipart/form-data-alternate$2 OLD_CONTENT_TYPE=$1$2
RequestHeader set Content-Type %{NEW_CONTENT_TYPE}e env=NEW_CONTENT_TYPE
</If>
@PechenkiUA
PechenkiUA / functions.php
Last active March 13, 2021 17:15
WooCommerce Distance Rate Shipping delivery_duration send telsender
<?php
/* WooCommerce Distance Rate Shipping delivery_duration send telsender */
function delivery_address_telsender ($list, $order_id){
$meter_duration = WC()->session->get('szbd_distance_car', false);
if ($meter_duration) {
$km = $meter_duration/1000;
$list['{delivery_duration}'] = round($km,2).' км';