Skip to content

Instantly share code, notes, and snippets.

@eto4detak
eto4detak / find.js
Created October 9, 2018 14:30
js find array obj
var indexOf = function (arr, id) {
for(var idx = 0, l = arr.length;arr[idx] && arr[idx].title !== id;idx++);
return idx === l ? -1 : idx;
};
убрать кэш
@eto4detak
eto4detak / create-attribute.php
Created October 17, 2018 12:49
woocommerce php create attribute
<?php
function proccess_add_attribute($attribute)
{
global $wpdb;
// check_admin_referer( 'woocommerce-add-new_attribute' );
if (empty($attribute['attribute_type'])) { $attribute['attribute_type'] = 'text';}
if (empty($attribute['attribute_orderby'])) { $attribute['attribute_orderby'] = 'menu_order';}
@eto4detak
eto4detak / add-custom-attribute.php
Last active October 17, 2018 16:04
woocommerce add custom attribute
<?php
add_action('init', 'generate_taxonomy_product');
function generate_taxonomy_product($value=''){
$my_product_attributes = array('hdd1' => 'qqqqqq', 'ram2' => 'wwwwwww');
wcproduct_set_attributes(10807, $my_product_attributes);
}
@eto4detak
eto4detak / delete_product.php
Created October 17, 2018 15:46
woo delete product
<?php
$args = array(
'post_type' => array( 'product_variation',),
// 'post_status' => array( //(string / array) - use post status. Retrieves posts by Post Status, default value i'publish'.
// // 'publish', // - a published post or page.
// // 'pending', // - post is pending review.
@eto4detak
eto4detak / variation-attribute.php
Last active November 21, 2018 11:13
woo update variation attribute
<?php
add_action('init', 'update_attributes_variation_product');
function add_variation_product($post_id){
$cars = array('c1', 'c2', 'c3' );
$info = array('ww' );
$att_all = [];
$att_all['car'] = $cars;
$att_all['info'] = $info;
@eto4detak
eto4detak / field-to-cart.php
Created October 19, 2018 10:47
woo add field to cart
<?php
// add_action('woocommerce_before_add_to_cart_button','wdm_add_custom_fields');
add_filter('woocommerce_add_cart_item_data','wdm_add_item_data',10,3);
add_filter('woocommerce_get_item_data','wdm_add_item_meta',10,2);
add_action( 'woocommerce_checkout_create_order_line_item', 'wdm_add_custom_order_line_item_meta',10,4 );
function wdm_add_custom_fields()
{
@eto4detak
eto4detak / include_once_wp-load.php
Created November 6, 2018 15:01
wp php включать wp-load.php
<?php
// /включать wp-load.php
if(!defined(ABSPATH)){
$pagePath = explode('/wp-content/', dirname(__FILE__));
include_once(str_replace('wp-content/' , '', $pagePath[0] . '/wp-load.php'));
}
@eto4detak
eto4detak / delete-files.php
Last active June 26, 2019 14:17
php delete-files
<?php
/**
* Delete old LOG files
*/
$path = $this_dir . '/logs/';
$days = 90;
// Open the directory
if ($handle = opendir($path)) {
// Loop through the directory
@eto4detak
eto4detak / update-product.php
Last active June 27, 2019 16:15
woo php update-product
<?php
foreach ($product_list as $data) {
// код 1С; артикул (ориентироватья ненадо); 0 нет в наличии > 0 в наличии; цена
$sku = trim($data[0]); // код 1С
$sku = $data[1]; // артикул (ориентироватья ненадо)
$quantity = $data[2]; // нет в наличии > 0 в наличии
$price = $data[3]; // цена
$found = false;