简体   繁体   中英

How to make a wordpress theme woocommerce compatible?

How can I make a wordpress theme woocommerce compatible ? I want to make cart page, my account page, product loop page, product single page,checkout page design into my wordpress theme.

We Can make WordPress theme compatible with woocommerce here is how you can do that

  • There are two ways to resolve this:

    1] Using woocommerce_content() -

    This solution allows you to create a new template page within your theme that will be used for all WooCommerce taxonomy and post type displays.
    To set up this template page, perform the following steps:

    • Duplicate page.php -

      Duplicate your theme's page.php file, and name it woocommerce.php. This file should be found like this: wp-content/themes/YOURTHEME/woocommerce.php.

    • Edit your page (woocommerce.php) -

      Open up your newly created woocommerce.php in a text editor, or the editor of your choice.

    • Replace the loop -

      In woocommerce.php, replace the Loop with woocommerce_content();

      ie, instead of if(have_posts)… endif; should be replaced by woocommerce_content()

      This will ensure that the WooCommerce templates are picked up for the product and taxonomy pages.

    2] Using WooCommerce Hooks -

    The hook method is more involved that using woocommerce_content, but is more flexible. This is similar to the method we use when creating our themes. By inserting a few lines in your theme's functions.php file, First unhook the WooCommerce wrappers;

    remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

    Then hook in your own functions to display the wrappers your theme requires:

    add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10); add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10); function my_theme_wrapper_start() { echo '<section id="main">';} function my_theme_wrapper_end() { echo '</section>';}

    3] Declare WooCommerce support -

    Now that you have made the changes, the final thing you have to do, is specify that your theme now supports WooCommerce. You need to add the following in functions.php of your theme. add_action( 'after_setup_theme', 'woocommerce_support' ); function woocommerce_support() { add_theme_support( 'woocommerce' ); }

To make it more practical for you this is the video for you, which you can follow too- How To Make WordPress Theme Compatible With WooCommerce Plugin

You need to install WooC and look at the all the style tags that come accross with it then you can style up the pages and add all of that to your style sheet.

Also you can use hooks but Im not 100% sure how you would check if WooC is active off the top of my head so that hooks in your code only come up when the plugin is active.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM