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 / 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 / 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)
{
//...
@moskalukigor
moskalukigor / SEARCH FROM ALL POST TYPE
Created November 15, 2016 09:05
SEARCH FROM ALL POST TYPE
function rc_add_cpts_to_search($query) {
// Check to verify it's search page
if( is_search() ) {
// Get post types
$post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
$searchable_types = array();
// Add available post types
if( $post_types ) {
foreach( $post_types as $type) {
$searchable_types[] = $type->name;
@moskalukigor
moskalukigor / Create order programmatically
Created November 15, 2016 09:13
Create order programmatically
function createCustomOrder($products, $posted_data) {
global $woocommerce;
$address = array(
'first_name' => $posted_data["popup-name"],
'last_name' => '',
'company' => $posted_data["popup-company"],
'email' => $posted_data["popup-email"],
'phone' => $posted_data["popup-phone"],
'address_1' => $posted_data["popup-address"],