• Resolved joycegrace

    (@joycegrace)


    Hello,

    The explanation below is a bit long, but my question is:

    How can I correctly unload this plugin’s back-end block editor styles, so that I can use only the styles I need in my child theme?

    Or will that ‘break’ the block editor, and give me the unpredictable results I was getting by using the code mentioned above?

    What else can I unload that I’m not using right now, for the back end styles and scripts, if I’m only using the hand-picked product block?

    Thank you for your help.

    The backstory:

    I’m trying to make my own styled version of a featured product. I don’t see how the ‘background’ photo on the current featured block plugin makes sense, when all other ‘default’ WC products are not formatted that way. It messes up the styling. Just an opinion, but letting you know why I’m not using the existing featured product block.

    I saw there is a ‘handpicked products’ block.

    I used that for one product, set it to one column, and then began styling its front-end display in my theme’s style.css to get it to look like this: https://cloudup.com/cMG5JUHQWI9

    That’s great.

    The problem is, the back-end block editor keeps taking styles from plugin files in /woo-gutenberg-products-block/build/wc-blocks-editor-style.css

    I need to override the styles for this one block only. I don’t need the rest of the plugin (right now).

    I create a file using the above path into my child theme hoping it would override styles in the block editor. In other words, a file named wc-blocks-editor-style.css containing my custom styles is now in:

    my-child-theme/woo-gutenberg-products-block/build/wc-blocks-editor-style.css

    I also added the following code in functions.php to get the plugin to use my custom styles:

    / Adds support for editor styles.
    add_theme_support( 'editor-styles' );
    
    // Enqueues editor styles.
    add_editor_style( '/woo-gutenberg-products-block/build/wc-blocks-editor-style.css' );

    It has reformatted the block in the block editor, which is great.

    But I don’t need the extras that WooCommerce blocks is loading in the back end. I want to reduce bloat as much as possible since our back end is getting slow.

    If I disable the block editor styles completely, using this method:

    /**
     * Disable WooCommerce block styles (back-end).
     */
    function slug_disable_woocommerce_block_editor_styles() {
      wp_deregister_style( 'wc-block-editor' );
      wp_deregister_style( 'wc-block-style' );
    }
    add_action( 'enqueue_block_assets', 'slug_disable_woocommerce_block_editor_styles', 1, 1 );

    Then I get this error:

    Screen Shot 2021 07 17 at 2 12 04 PM

    Or a blank white screen. Or a notice to attempt block recovery. It depends on which ‘hard refresh’ I’m doing, and it seems to be random results each time (I keep refreshing consecutively). Sometimes, when refreshing, I get the ‘regular’ block editor showing the above hand-picked product block that I’ve restyled, but it still loads the plugin’s files.

    Does anyone know a good solution for what I’m trying to do here?

    I don’t want to go through the trouble of creating my own custom blocks for this one thing. I just want to disable what I’m not using in an already-working plugin, which can come in handy later on. Then, when I need other features, I’d like to enable them later.

    It seems like it should be a lot simpler than it is…but I can’t figure it out. Sorry ??

    • This topic was modified 3 years, 4 months ago by joycegrace.
    • This topic was modified 3 years, 4 months ago by joycegrace.
Viewing 9 replies - 1 through 9 (of 9 total)
  • This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter joycegrace

    (@joycegrace)

    Interesting. I thought it would be as simple as deregistering certain styles or functions or something, the way that I was able to do for the front-end. I appreciate it can be more complex, and that’s also good for me to know. I have posted this in Slack, in hopes that a nice, helpful human can shed light on this. I’m not a full-on developer so I think the developer resources would be a bit tough for me at this stage in my learning. Thank you anyway.

    Hey @joycegrace I think this following plugin will help you with you problem.

    https://www.ads-software.com/plugins/disable-dashboard-for-woocommerce/

    Thread Starter joycegrace

    (@joycegrace)

    @mohitmishra I am aware of this plugin and it does not offer any options to disable anything to do with WooCommerce blocks. It also does not offer any options to selectively disable specific blocks on the back end within the WooCommerce blocks plugin.

    Stef

    (@serafinnyc)

    Have you tried using jQuery?

    If I understand you correctly you’re trying to move a few items from one core file for blocks is that right?

    @joycegrace Did you ever find a solid solution? I have tried many variations of the wp_deregister_style( 'wc-block-style' ); and none of them work for me. Always, /wp-content/plugins/woocommerce/packages/woocommerce-blocks/build/wc-blocks-style.css loads despite efforts to remove.

    Plugin Support Ryan Ray, a11n

    (@ryanr14)

    Howdy @joycegrace & @roadsunknown,

    Would any solutions shown in this Stack Overflow post help? I assume you’ve seen them before? ??

    https://stackoverflow.com/questions/52277629/remove-gutenberg-css

    I think the trick being the wp_dequeue_style instead of wp_deregister_style. Hopefully.

    I have tried both wp_dequeue_style and wp_deregister_style previously. Giving it yet another try, this time using wc-blocks-styles (note the plural s – which I also tried previously), something seems to have finally taken. I have kept both just in case:

    function ca_deregister_woocommerce_block_styles() {
     	wp_deregister_style( 'wc-blocks-style' );
    	wp_dequeue_style( 'wc-blocks-style' );
    }
    add_action( 'enqueue_block_assets', 'ca_deregister_woocommerce_block_styles' );

    Why wc-blocks-style vs. wc-block-style as referenced by most all StackOverflow and blog posts? This seems to be where the styles are registered:

    https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/6da64165025e7a2afc1782e4b278d72536e7b754/src/AssetsController.php#L49

    $this->register_style( 'wc-blocks-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks-style', 'css' ), __DIR__ ), [ 'wc-blocks-vendors-style' ], 'all', true );

    Plugin Support Ryan Ray, a11n

    (@ryanr14)

    Thanks for the update @roadsunknown,

    Glad you have something that is certainly working. I’ve not had a moment to try and test this myself, but I’ll aim to ASAP and try to follow up here with what I find.

    Perhaps as well another community member will beat me to it as well. ??

    Thanks again!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to disable block editor styles for WooCommerce blocks?’ is closed to new replies.