Skip to content

Instantly share code, notes, and snippets.

View ucheng's full-sized avatar
💭
😄

Yu-Cheng Wang ucheng

💭
😄
View GitHub Profile
<?php
add_filter( 'product_type_selector', 'remove_product_types' );
function remove_product_types( $types ){
unset( $types['grouped'] );
unset( $types['external'] );
return $types;
}
@ucheng
ucheng / ob_start.php
Created June 2, 2017 15:12
shortcode ob_start
<?php
add_shortcode('prefix_shortcode', 'prefix_shortcode');
function prefix_shortcode() {
ob_start();
?>
//your html
<?php
$output_string = ob_get_contents();
<?php
//處理訂單狀態
add_filter( 'handle_bulk_actions-edit-shop_order', 'wootest_handle_bulk_actions_edit_product', 10, 3 );
function wootest_handle_bulk_actions_edit_product( $redirect_to, $action, $post_ids ) {
global $typenow;
$post_type = $typenow;
if( $post_type == 'shop_order' ) {
$wp_list_table = _get_list_table('WP_Posts_List_Table');
@ucheng
ucheng / custom-order-status.php
Last active May 18, 2017 05:51
客製化訂單狀態
<?php
function register_awaiting_shipment_order_status() {
register_post_status( 'wc-awaiting-shipment', array(
'label' => '等待運送',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( '等待運送 <span class="count">(%s)</span>', '等待運送 <span class="count">(%s)</span>' )
) );
@ucheng
ucheng / woo-default-user-role.php
Last active April 24, 2017 15:58
change the default user role for woocommerce register user
<?php
add_filter( 'woocommerce_new_customer_data', 'my_new_customer_data');
function my_new_customer_data($new_customer_data){
$new_customer_data['role'] = get_option( 'default_role' );
//$new_customer_data['role'] = 'vip';
return $new_customer_data;
}
@ucheng
ucheng / wc-order-custom-status.php
Created March 21, 2017 14:07
get woo orders with custom status
<?php
$orders = get_posts( array(
'post_type' => 'shop_order',
'post_status' => array('wc-packing')
));
<?php
function themeslug_customize_register( $wp_customize ) {
// Do stuff with $wp_customize, the WP_Customize_Manager object.
}
add_action( 'customize_register', 'themeslug_customize_register' );
@ucheng
ucheng / remove_capital_p.php
Created October 28, 2016 16:52
remove capital_p
<?php
remove_filter( 'the_title', 'capital_P_dangit', 11 );
remove_filter( 'the_content', 'capital_P_dangit', 11 );
remove_filter( 'comment_text', 'capital_P_dangit', 31 );
@ucheng
ucheng / remove_avada_button.php
Created September 29, 2016 14:04
remove Avada mce button
<?php
add_filter('mce_buttons','prefix_tinymce_buttons', 12);
function prefix_tinymce_buttons($buttons) {
$user = wp_get_current_user();
if ( $user->roles[0] == 'administrator' ) {
return $buttons;
}
//Remove the text color selector
@ucheng
ucheng / add_membership.php
Last active September 26, 2016 15:07
Add Membership to Woo Customer (For WooCommerce Memberships)
<?php
//remove the following code after membership is added
add_action( 'init', 'myprefix_add_membership');
function myprefix_add_membership() {
$customers = get_users('role=customer');
$plan_id = 21356;//一般會員
foreach( $customers as $customer ):
$normal_membership = wc_memberships_get_user_membership( $customer->id, 'normal');
if ($normal_membership) {
continue;