Wordpress钩子函数
# 图片类 hook
# jpeg_quality
修改图片上传后压缩质量(或关闭)
# 修改压缩质量代码
add_filter('jpeg_quality', function($arg){return 90;});
# 关闭图片上传后压缩
add_filter('jpeg_quality', function($arg){return 100;});
1
2
3
4
5
6
2
3
4
5
6
# big_image_size_threshold
关闭图片限制2560 pixels
add_filter( 'big_image_size_threshold', '__return_false' );
1
# 产品类 hook
# wc_product_sku_enabled
商品是否公开显示barcode
# Instructions
/**
* 隐藏商品barcode
*/
#add_filter( 'wc_product_sku_enabled', '__return_false' );
function sv_remove_product_page_skus( $enabled ) {
if ( ! is_admin() && is_product() ) {
return false;
}
return $enabled;
}
add_filter( 'wc_product_sku_enabled', 'sv_remove_product_page_skus' );
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 订单类 hook
# 自定义地址 states
# Instructions
/**
* Add or modify States
*/
add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
function custom_woocommerce_states( $states ) {
$states['NZ'] = array(
'AK' => 'Auckland',
'SL' => 'Southland',
'NL' => 'Northland'
);
return $states;
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 强制订单字段必填
# instructions
add_filter( 'woocommerce_default_address_fields' , 'make_state_field_required', 90, 1 );
function make_state_field_required( $address_fields ) {
$address_fields['state']['required'] = true;
return $address_fields;
}
1
2
3
4
5
2
3
4
5
# API类 hook
# 限制API batch数量
# instructions
function wpse_rest_batch_items_limit( $limit ) {
$limit = 500;
return $limit;
}
add_filter( 'woocommerce_rest_batch_items_limit', 'wpse_rest_batch_items_limit' );
1
2
3
4
5
6
2
3
4
5
6
上次更新: 2023/10/18, 08:38:42