Skip to content

Instantly share code, notes, and snippets.

View moskalukigor's full-sized avatar

Ihor moskalukigor

View GitHub Profile
@moskalukigor
moskalukigor / Register ACF Option
Last active November 9, 2016 13:05
Register ACF Option
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'Theme Header Settings',
@moskalukigor
moskalukigor / cf7 get field and skip mail
Last active November 9, 2016 13:05
cf7 get field and skip mail
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");
function wpcf7_do_something_else($cf7) {
$wpcf = WPCF7_ContactForm::get_current();
$wpcf->skip_mail = true;
$cookieForm = array(
'billing_first_name' => $_POST["text-873"],
'billing_last_name' => $_POST["text-251"],
);
@moskalukigor
moskalukigor / Remove Fields from checkout page
Created November 9, 2016 13:07
Remove Fields from checkout page
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 10, 1 );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_phone']['required'] = false;
unset($fields['billing']['billing_phone']['validate']);
$fields['billing']['billing_country']['required'] = false;
unset($fields['billing']['billing_country']['validate']);
unset($fields['billing']['billing_country']);
@moskalukigor
moskalukigor / CYR TO LAT
Last active November 9, 2016 13:33
CYR TO LAT
/*
Plugin Name: Cyr to Lat enhanced
Plugin URI: http://wordpress.org/plugins/cyr3lat/
Description: Converts Cyrillic, European and Georgian characters in post, term slugs and media file names to Latin characters. Useful for creating human-readable URLs. Based on the original plugin by Anton Skorobogatov.
Author: Sol, Sergey Biryukov, Nikolay Karev, Dmitri Gogelia
Author URI: http://karevn.com/
Version: 3.5
*/
function ctl_sanitize_title($title)
{
@moskalukigor
moskalukigor / Remove Fields from Checkout Page v2
Last active November 9, 2016 14:29
Remove Fields from Checkout Page v2
add_filter("woocommerce_checkout_fields", "order_fields");
function order_fields($fields) {
//Show only fields: fname,lname
$order = array(
"billing_first_name",
"billing_last_name",
);
foreach($order as $field)
{
@moskalukigor
moskalukigor / functions.php
Last active September 14, 2017 08:36
Wordpress Ajax
<?php
/*IS NOT WOOCOMMERCE*/
if ( ! function_exists( 'is_ajax' ) ) {
/**
* is_ajax - Returns true when the page is loaded via ajax.
* @return bool
*/
function is_ajax() {
return defined( 'DOING_AJAX' );
}
@moskalukigor
moskalukigor / set popularity product
Created November 11, 2016 14:35
set popularity product
//set popularity product
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
@moskalukigor
moskalukigor / StdClass to Array (arrayCastRecursive)
Created November 11, 2016 14:36
StdClass to Array (arrayCastRecursive)
function arrayCastRecursive($array)
{
if (is_array($array)) {
foreach ($array as $key => $value) {
if (is_array($value)) {
$array[$key] = arrayCastRecursive($value);
}
if ($value instanceof stdClass) {
$array[$key] = arrayCastRecursive((array)$value);
}
@moskalukigor
moskalukigor / Create order programmatically and redirect to payment
Created November 14, 2016 09:56
Create order programmatically and redirect to payment
//AUTHOR: Ronn0 ( stackoverflow.com 31787244 )
if (isset($_POST['isOrder']) && $_POST['isOrder'] == 1) {
$address = array(
'first_name' => $_POST['notes']['domain'],
'last_name' => '',
'company' => $_POST['customer']['company'],
'email' => $_POST['customer']['email'],
'phone' => $_POST['customer']['phone'],
'address_1' => $_POST['customer']['address'],
@moskalukigor
moskalukigor / Get Cart items Woocommerce
Created November 14, 2016 12:51
Get Cart items Woocommerce
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values )
{
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
if ( $found == true)
{
//...