Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor header.php and enable Woo parts if WooCommerce is installed #461

Conversation

crftwrk
Copy link
Member

@crftwrk crftwrk commented Apr 22, 2023

In relation to #460

This PR uses get_template_part to get header buttons/widgets. WooCommerce related items load when WooCommerce is installed. No 2 different header.php's needed anymore.

  • No breaking changes to existing bootcommerce-child installations
  • Allows us to delete header.php in bootcommerce-child

How to test

Test in main-theme

  • Remove // comments in main.scss line 4 to enable Woo styles
  • Add following snippet to functions.php to enable Woo scripts if Woo is installed
if ( class_exists( 'WooCommerce' ) ) {

  require get_template_directory() . '/woocommerce/woocommerce-functions.php';
  
  function my_function() {
    echo '<p class="alert alert-success">Woo installed</p>';
  }
  add_action('bs_after_primary', 'my_function', 5);

} else {

function my_function_2() {
    echo '<p class="alert alert-warning">Woo NOT installed</p>';
  }
  add_action('bs_after_primary', 'my_function_2', 5);

}
  • Enable/disable WooCommerce plugin in backend and check the header in frontend
  • Install a usual bootscore-child and override parts or entire header templates

@justinkruit

  • If you like it, merge it
  • Is there a way to add _bscore_woocommerce.scss to the compiler and enable file only if WooCommerce is installed?

@justinkruit
Copy link
Member

Maybe an idea to move the files a bit? Instead of them being named header-top-nav-search-collapse-woocommerce.php, name them header/top-nav-search-collapse-woocommerce.php, and that way you can call this one via get_template_part('template-parts/header/top-nav-search-collapse', 'woocommerce'); (as woocommerce is a variant of that file)

@crftwrk
Copy link
Member Author

crftwrk commented May 2, 2023

Good idea, pls check. I removed some comments because snippets speak by itself.

Copy link
Member

@justinkruit justinkruit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, good job on this 👍

@justinkruit justinkruit merged commit ff1cd76 into main May 7, 2023
@justinkruit justinkruit deleted the Refactor-header.php-and-enable-Woo-parts-if-WooCommerce-is-enabled branch May 7, 2023 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants