Skip to content

Instantly share code, notes, and snippets.

@eto4detak
eto4detak / page-template.php
Created November 6, 2018 18:35
wp php page template header
<?php
/*
Plugin Name: Movie Reviews
Plugin URI: http://wp.tutsplus.com/
Description: Declares a plugin that will create a custom post type displaying movie reviews.
Version: 1.0
Author: Soumitra Chakraborty
Author URI: http://wp.tutsplus.com/
License: GPLv2
*/
@eto4detak
eto4detak / cron.php
Last active October 19, 2019 06:50
wp php cron
* * * * * php /var/www/project/yii mailer/send
<?php
// регистрируем пятиминутный интервал
add_filter( 'cron_schedules', 'cron_add_five_min2234124124124' );
function cron_add_five_min2234124124124( $schedules ) {
$schedules['twenty_min_аaa'] = array(
'interval' => 60 * 20,
'display' => 'Раз в 20 минут'
);
@eto4detak
eto4detak / order get metadata.php
Created November 7, 2018 21:24
woo php order get metadata
<?php
//получить Id заказов бронирования авто
public static function get_orders_ids($order_status = array('wc-completed')){
global $wpdb;
$product_id = self::$settings['woo_id_product'];
$results = $wpdb->get_col("
SELECT order_items.order_id
FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
@eto4detak
eto4detak / date.js
Created November 7, 2018 22:35
js date
Date.prototype.yyyymmdd = function() {
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
return [this.getFullYear(),
(mm>9 ? '' : '0') + mm,
(dd>9 ? '' : '0') + dd
].join('/');
};
Jan02_1970.yyyymmdd()
@eto4detak
eto4detak / date.php
Last active September 16, 2019 13:33
php date
<?php
$str = '15:17 14.09.2019';
$d = strtotime($str);
echo date_diff(new DateTime(), new DateTime('15:17 15.09.2019'))->days;
// format
$str = '2019-07-27T10:44:15+10:00';
$d = date("jS F, Y", strtotime($str));
@eto4detak
eto4detak / woo-sql.php
Last active June 22, 2019 06:53
woo sql php
<?php
//получить Id заказов бронирования авто
public static function get_orders_ids($order_status = array('wc-completed', 'wc-on-hold')){
global $wpdb;
$product_id = self::$settings['woo_id_product'];
$results = $wpdb->get_col("
SELECT order_items.order_id
FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
@eto4detak
eto4detak / rating.php
Last active May 26, 2019 12:16
woo php rating
<?php
// show rating plagin
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_custom_action', 15 );
function bbloomer_custom_action() {
if(function_exists('the_ratings')) { the_ratings(); }
}
//
add_action( 'comment_form_logged_in_after', 'extend_comment_custom_fields' );
@eto4detak
eto4detak / field-general.php
Last active April 8, 2019 13:01
wp php register_setting field-general
<?php
function divie_add_option_field_to_general_admin_page(){
$option_name = 'divie_company_location';
register_setting( 'general', $option_name );
add_settings_field(
'myprefix_setting-id',
'Локация компании',
'divie_setting_callback_location_gen_opt',
'general',
@eto4detak
eto4detak / dowload-file.php
Last active August 30, 2019 21:03
wp php dowload file
<?php
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$file_array = [];
$tmp = download_url($this->infoProduct[0]['image_src'][0]);
preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $this->infoProduct[0]['image_src'][0], $matches );
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
@eto4detak
eto4detak / prepare_attributes.php
Created November 24, 2018 19:36
woo php prepare_attributes
<?php
$data = [
'attribute_names' => ['pa_article','pa_land'],
'attribute_values' => ['279','222'],
'attribute_position' => ['0','0'],
'attribute_visibility' => ['1','1'],
];
$attributes = WC_Meta_Box_Product_Data::prepare_attributes( $data );