How to programmatically edit woocommerce shopping page (CSS and PHP)

Template files are rarely updated. functions. The problem with PHP file operation is that after adding a hook, the default woocommerce shopping page will still be displayed. Therefore, to create a template from scratch, you must first disable the default woocommerce template store page. archive-product. The file responsible for the output of the store page in the woocommerce. PHP file is archive product. It is PHP and can be found in the woocommerce Templates folder (woocommerce > Templates > archive product. PHP).
To overwrite the file, you must copy and paste it into the woocommerce folder of the sub theme, as follows: Now Archive – product. Check the PHP file to see how woocommerce displays the store page. To do this, open the preferred integrated development environment (IDE), navigate to the template folder of the woocommerce plug-in, and open the file. Edit and play the same way you customize other WC template files. Before doing so, make sure the original file is backed up so that you can cancel the changes as needed.
archive-product. You can see several do_action () functions in the PHP file. This function is used to create the currently available woocommerce hook for the store page. To completely disable the woocommerce shopping page, simply delete the loop responsible for printing the product. If (wc_get_loop_prop){
Have_posts (){
the_post();
Do_action (\
Wc_get_template_part (\
}
}You can make further changes here, but for simplicity, just delete the ring and keep everything else. If you decide to make more changes, if you delete a part of the do_action() function, the shortcut code will no longer work on all pages of the website.
If you delete a product print loop, archive product. The PHP file is shown as follows: Defined (\
Get_header (\
do_action(‘woocommerce_before_main_content’);
if (woocommerce_product_loop()) {
do_action(‘woocommerce_before_shop_loop’);
\/\/The ring is deleted here.
do_action(‘woocommerce_after_shop_loop’);
}Another{
do_action(‘woocommerce_no_products_found’);
}
do_action(‘woocommerce_after_main_content’);
Do_action (\
Get_footer (\
That’s all! Disable the default store page template and edit the woocommerce store page programmatically! The store page is now empty and you can start your own design.
2. In the male programming mode, the title and content of the woocommerce shopping page can be customized. The content and title can be HTML annotations containing images, tables or links. Alternatively, it is an empty container for running external JavaScript files. To do this, we will use the woocommerce shortcut code to display products on the store page, so we need basic knowledge. If you are not familiar with WC shortcuts, please check this guide. Now let’s edit the wcshopping page to display products by most popular, best sellers, highest ratings and categories. In addition, the outer ring
ucts limit=\
Function shop_main_heading(){
$content=“”;
$content.=’ Welcome to my wonderful shopping page!
‘;
$content.=’ Male built with love;
$content.=’ Thank you for visiting the shopping page of my website. Search for your favorite products and buy them all. ‘;
$content.=’ ‘;
Eco $content;
}
The shopping page is displayed as follows: Use woocommerce_after_shop_loop hook in the same way to display some contents at the end of the store page. Hemp. Male edit the number of products per line and apply CSS style sheet to wcshopping page. Now you can use woocommerce shortcut code to display products and sort them by recommendation, classification, best seller and other required methods. In addition, you must be able to insert all types of content anywhere on the shopping page. But what if you could go further and take the shopping page to the next level? You can edit the template layout and add some CSS styles to further customize the woocommerce shopping page programmatically. 3.1 by specifying the default number of columns for each row and editing the column attribute of WC shortcut code, you can set the number of products displayed per row. You can also use the limit property to set the total number of products for the shortcut code. [product orderby = \
if
Let me assume. For example, to display 10 products per page, use functions. Simply add the following code to the PHP file: add_filter( ‘loop_shop_per_page’, ‘new_loop_shop_per_page’, 20 );
Function new_loop_shop_per_page ($cols){
$cols = 10;
Return $cols.
}Where, $cols contains the number of products per page. These pages get values from options – > read and return the number of products displayed on each page. 4. Edit the circular file of the woocommerce shopping page. So far, in order to customize the woocommerce shopping page programmatically, we use archive product. See how to edit the PHP template file. This file is where the WC cycle runs and is used to display all products on the page. Now open the woocomer plug-in folder in the plug-in editor or IDE, and then open the ring folder. archive-product. You can find it at the same level as the PHP file. You can edit in the ring folder and find some files so that you can further customize the shopping page. To overwrite this file, you must create folders and files copied to the subtopics. Under the previously created woocommerce folder, create a new folder named loop. Then select the original sale flash from the plug-in template. Copy the PHP file and paste it into the ring folder of the sub theme. sale-flash. Add animated gifs to all products in PHP. As can be seen from the file, the script displays the \
Global $post, $product;
if ( $product->is_on_sale() ) {
$an_gif = ‘
‘;
Eco$an_gif;
}
There, you can replace the GIF file with another GIF as needed. 4.2 remove sorting options and pagination. Now let’s see how to disable the \
This will show a cleaner header and footer on the shopping page. In addition, pagination may not be useful because a large number of products are displayed.

sale-flash. Remove the default woocommerce action from the PHP file and add its own action to display the animated GIF. This is a very basic work, but the technology provides a wide range of possibilities for senior developers. Final note when woocommerce decides to publish a template update, the WC template file of the sub theme will not prevent overwriting. But it hardly happens. They are sample scripts and should not be used in production, but only for training purposes. Bonus: show categories on the woocommerce shop page. Finally, let’s see how to use some code to add categories to the woocommerce shop page. It is recommended that users with coding technology use this method. In addition to PHP, it is also recommended that you learn some CSS to specify code styles. Note: back up your site before you start. If not, create a sub theme.
On the add category to shopping page dashboard, navigate to shape > Theme Editor to implement the sub theme function. Open the PHP file. Right click functions in the topic file sidebar. Click the PHP file and paste the following script to add custom functionality: The following features will add product categories before loading other elements in the shopping page. That is, shoppers can view all product categories before viewing the product catalog. Function product_subcategories ($args = array()){
$parentid = get_queied_object_id();
$args = array(
\
);
$terms = get_terms( ‘product_cat’, $args );
if ( $terms ) {
echo ‘

‘;
foreach ( $terms as $term ) {
echo ‘‘;
woocommerce_subcategory_thumbnail( $term );
Echo \
echo ‘

slug . ‘ \
Echo $term – > name;
Echo \
Echo \
Echo \
}
Echo \
}
}
add_action( ‘woocommerce_before_shop_loop’, ‘product_subcategories’, 50 ); This function adds categories to the woocommerce shop page. However, because it may not be displayed exactly as needed, you need to specify the style of the new category section with a little CSS. For more information, see the post on the store page about how to display categories and specify styles. Conclusion in general, store pages are very important and can create or break stores. Therefore, if you have coding technology, it is best to edit and optimize the woocommerce shopping page programmatically to improve the conversion rate. This guide explains how to add, remove, and customize all aspects of a store. But these are just a few examples and ideas that can help you find inspiration and further develop the store. Now it’s time to play and develop customizations. To view more guidelines for customizing the woocommerce store, it is recommended that you check the following: How to add custom fields to the woocommerce Ajax shopping cart settlement page? Programmatically add functionality to the woocommerce shopping cart. Finally, to associate Facebook shop with woocommerce, you need to review the entire guide. Have you customized the online store? What have you changed? If you have any questions, please leave a message below. I will do my best to help you! GitHub can also check the complete code.

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *