Skip to content

Instantly share code, notes, and snippets.

View sutandang's full-sized avatar

eringga sutandang

  • indonesia
  • yogyakarta , indonesia
View GitHub Profile
add_action( 'woocommerce_product_after_variable_attributes','variation_settings_fields', 10, 3 );
// Save Variation Settings
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
/**
* Create new fields for variations
*
*/
function variation_settings_fields( $loop, $variation_data, $variation ) {
// Text Field
woocommerce_wp_text_input(
@sutandang
sutandang / Filter Wordpress media by user
Created June 6, 2017 16:17
Filter Wordpress media by user
add_action('pre_get_posts', 'um_filter_media_files');
add_filter('wp_count_attachments', 'um_recount_attachments');
function um_recount_attachments($counts_in){
global $wpdb;
global $current_user;
$and = wp_post_mime_type_where(''); // Default mime type // AND post_author = {$current_user->ID}
@sutandang
sutandang / Basic PSR 4 autoloader
Last active June 6, 2017 16:16
Basic PSR 4 autoloader
<?php
// Inside MyApp/ create composer.json with the below contents
{
"require": {
},
"autoload": {
"psr-4": {
"MyApp\\": ["src/", "tests/"]
}
}
@sutandang
sutandang / default page woocommerce
Last active June 6, 2017 16:13
how to create default page woocommerce
function azweb_marketplace_wc_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
global $wpdb;
$option_value = get_option( $option );
if ( $option_value > 0 ) {
$page_object = get_post( $option_value );
if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
return $page_object->ID;
@sutandang
sutandang / add front end menu , programitically
Created June 6, 2017 16:04
add front end menu , programitically
function new_nav_menu_items($items) {
$homelink = '<li class="home"><a href="' . home_url( '/solutions' ) . '">' . __('Solutions') . '</a></li>';
$items = $homelink . $items;
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
@sutandang
sutandang / edit label in wordpress
Created June 6, 2017 15:49
edit label in wordpress
function my_custom_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Show all product types' :
$translated_text = __( 'Show all solutions types', 'woocommerce' );
break;
case 'Sort Products' :
$translated_text = __( 'Show Solutions', 'woocommerce' );
break;
case 'Product Data' :
$translated_text = __( 'Solutions Data', 'woocommerce' );
@sutandang
sutandang / add row to wordpress admin post type
Created June 6, 2017 15:47
how to add row to wordpress admin post type
add_filter('manage_inquiry_posts_columns', 'custom_table_head');
function custom_table_head( $defaults ) {
$defaults['author'] = 'Inquiry By';
$defaults['date'] = 'Created Date';
return $defaults;
}
@sutandang
sutandang / alert-message-custome-wordpress
Created June 6, 2017 15:44
How to update message alert in custome post type wordpress
add_filter( 'post_updated_messages', 'update_new_messages' ,100);
function update_new_messages( $messages ) {
$post = get_post();
$post_type = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );
if($post_type != 'product')
return;
@sutandang
sutandang / hooks-porduct-type
Created June 6, 2017 15:36
custom woocommerce product type in admin woocommerce / product tabs
<?php
add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' , 99 , 1 );
function add_my_custom_product_data_tab( $product_data_tabs ) {
/*
to remove this product type unset all product type
unset($product_data_tabs['general']);
unset($product_data_tabs['inventory']);
unset($product_data_tabs['shipping']);
unset($product_data_tabs['linked_product']);
@sutandang
sutandang / add wp media in front end wordpress
Created November 7, 2016 04:07
create wp upload in front end wordpres
1. load media in controller / function.php / plugins
```
function enqueue_media_scripts() {
if(function_exists('wp_enqueue_media')) {
wp_enqueue_media();
}
else {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');