Skip to content

Instantly share code, notes, and snippets.

@guytzhak
guytzhak / shipping_based_weight.php
Created February 15, 2022 08:49
Woocommerce Shipping based rate
add_filter( 'woocommerce_package_rates', 'ras_custom_shipping_costs', 20, 2 );
function ras_custom_shipping_costs( $rates, $package ) {
$weights_prices_field = get_field('shipping_weights', 'options');
$weights_prices = [];
foreach ($weights_prices_field as $weights_price) {
$weights_prices[floatval($weights_price['weight'])] = floatval($weights_price['price']);
}
foreach( $rates as $rate_key => $rate ){
// disable Gutenberg for posts
add_filter('use_block_editor_for_post', '__return_false', 10);
// disable Gutenberg for post types
add_filter('use_block_editor_for_page', '__return_false', 10);
add_filter('should_load_block_editor_scripts_and_styles', '__return_false', 10);
remove_theme_support( 'editor-color-palette' );
remove_theme_support( 'wp-block-styles' );
remove_theme_support( 'core-block-patterns' );
remove_theme_support( 'editor-gradient-presets' );
remove_theme_support( 'editor-font-sizes' );
add_filter( 'block_editor_settings' , [$this, 'remove_guten_wrapper_styles'] );
// disable Gutenberg for posts
add_filter('use_block_editor_for_post', '__return_false', 10);
// disable Gutenberg for post types
add_filter('use_block_editor_for_page', '__return_false', 10);
add_filter('should_load_block_editor_scripts_and_styles', '__return_false', 10);
remove_theme_support( 'editor-color-palette' );
remove_theme_support( 'wp-block-styles' );
remove_theme_support( 'core-block-patterns' );
function remove_guten_wrapper_styles(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'wc-block-style' ); // REMOVE WOOCOMMERCE BLOCK CSS
wp_dequeue_style( 'global-styles' ); // REMOVE THEME.JSON
}