Methods of adding woocommerce related products: 3 methods

More details. Therefore, if you want to learn more ways to customize woocommerce related products, I suggest you continue to read. Let’s start with the plug-in method that beginners are more familiar with. How to add woocommerce related products using plug-ins plug-ins is one of the easiest ways to add and customize related products. This plug-in is specifically designed to manually select products to be added to the relevant products section of woocommerce.
WordPress has several feature rich plug-ins. Some of them allow you to add customizable related sections that you can add to any part of the site. Provide fully customizable sliders and banners to perform other operations. Of course, the options for choosing a plug-in depend on the user. But today’s presentation will use custom related products referenced by Scott Nelle’s woocommerce plug-in. The plug-in works simply by specifying the products to be added to the related products of the desired products.
However, to start using the plug-in, you must first install and activate the plug-in. 1. Open the plug-in installation and activation WP management panel, and click plug-in > add to start. Then use the search pane in the upper right corner to search for woocommerce custom related products. Then, on the plug-ins tab, click Install Now and activate when the installation is complete. Now, you must complete the activation and installation of the plug-in. To use plug-ins that are not included in the word press repository, you must install them manually. If you need additional information, we will provide a detailed guide to help you manually install word press.
2. Through the commodity page, the relevant commodity addition plug-in itself can add the relevant product part to each specific product, thus playing a role. Specify and open the wooce product data. If the product is not added to the related products section, the plug-in will be replaced by the default woocomer action, which randomly selects the woocomer related products with tags. Therefore, on the WP Management Dashboard, reopen Products > all products, and then click Edit to add related products. This is the same as the previous method of woocommerce dashboard.
Scroll again under product data and click the connected product. A new field named related product must now be displayed. Now, you just need to manually enter the name of the product you want to add as a related product for a specific product. After updating the product, you can view the changes on the product page. Add woocommerce related products programmatically or use woocommerce plug-in to manage woocommerce related products. If you don’t want to customize, you can also choose to use code snippets to add. To this end, the function of the theme. You need to add a few lines of code to the PHP file. However, this method is only applicable if you have a basic understanding of programming.
It is recommended to create sub themes and back up the WordPress website. In this way, even if the WordPress theme is updated, the changes will be saved. If you need help, you can also use one of WordPress’s best sub theme plug-ins. After switching to a sub theme, click Shape > Theme Editor to implement the function. You can access PHP files. Then there is the topic function or function. Click the PHP file. Open the file in the theme editor. You can then paste it into the editor using the following code snippet: add_filter( ‘woocommerce_related_products’, ‘QuadLayers_re
lated_products_by_same_title’, 9999, 3 );
Functions quadlayers_related_products_by_same_title ($related_posts, $product_id, $args){
$product = wc_get_product( $product_id );
$title = $product->get_name();
$related_posts = get_posts (array)(
\
\
\
\
‘posts_per_page’ => -1,
\
));
$related_posts return;
}Male code snipet works by providing related products with the same name. If a product with the same name exists, it will be added to the relevant products section of woocommerce. Click file update to implement the function. Update the PHP file. Here is the credit card of the original author of the code. The method of deleting woocommerce related products can also choose to use the above method to delete the woocommerce related products section from the website. You can choose to delete all related products completely or only specific products. 1. Delete all related products, delete all related product parts from all product pages, and delete functions in sub topics. Just open the PHP file and paste the following code snippet. remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 ); Finally. Update file. This will completely remove the relevant product section from all woocommerce products. The coder is provided with credit here. 2. If you only need to delete the relevant products of a specific product, you can also use code snippets to delete only the relevant products of a specific product on the website. The following code adds only the options hidden in all products: First, the function of the theme is the same as before. Paste it into a PHP file. add_action( ‘woocommerce_product_options_general_product_data’, ‘QuadLayers_add_related_checkbox_products’ );
Functions quadlayers_add_related_checkbox_products(){
Woocommerce_wp_checkbox (array)(
‘id’ => ‘hide_related’,
\
\
)
);
}
\/\/ ——————————————
\/\/ 2. Save check box in custom field
add_action( ‘save_post_product’, ‘QuadLayers_save_related_checkbox_products’ );
Function quadlayers_save_related_checkbox_products ($product_id){
Global $pagenow, $typenow;
if ( ‘post.php’ !== $pagenow || ‘product’ !== $typenow ) return;
If (defined (\
if ( isset( $_POST[‘hide_related’] ) ) {
update_post_meta( $product_id, ‘hide_related’, $_POST[‘hide_related’] );
} else delete_post_meta( $product_id, ‘hide_related’ );
}
\/\/ ——————————————
\/\/ 3. Hide related products @ single product page
add_action( ‘woocommerce_after_single_product_summary’, ‘QuadLayers_hide_related_checkbox_products’, 1 );
Functions quadlayers_hide_related_checkbox_products(){
Global $product;
If (! If empty (get_post_meta ($product – > get_id(), \
remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 );
}
}On the WordPress dashboard, move to Products > all products again, and click Edit for the products you want to hide. When scrolling under product data, click the General tab, as shown in the previous method. New hide related product options must be displayed. To hide related products in a specific product page, enable this option. Here is the coder’s credit card. The method of customizing relevant product numbers and columns. You can also customize relevant product parts by configuring the number of products and rows and columns displayed on the website. To this end, we should play a role. You will use the woocommerce hook and custom functions in your PHP file. Continue using the theme editor to reopen the file and paste the following code snippet: add_filter( ‘woocommerce_output_related_products_args’, ‘QuadLayers_change_number_related_products’, 9999 );
Function quadlayers_change_number_related_products ($args){
$args[‘posts_per_page’] = 4; \/\/ Of related products#
$args [\
Return $args;
This code consists of 4 columns and 4 lines in the relevant product part of woocommerce$ Args [\
.site-main . related. products ul. products li. product {
Width: 22%;
towards the left
Blank right: 4%;
}Just paste it under the additional CSS of the theme customization tool. On the WordPress dashboard, click Shape > Customize to access. The theme customization program opens. Then click the other CSS tab and paste the CSS script here. You can adjust the ranking of related products according to the needs of the website. When you are finished, click publish. Here is the coder’s credit. Conclusion this concludes the guidelines for adding woocommerce related products. This is one of the best ways to improve the sales of e-commerce websites. However, if necessary, you can use this guide to add, customize, or delete. To sum up, you can add related products to woocommerce in the following three ways: The woocomerce dashboard also includes several steps that help you customize these related products by using plug-in programming. This includes deleting products from the products page and modifying the related products and their number of columns. I hope it can also be helpful when adding related products. Customized woocommerce related products
The detailed tutorial provides more information. For more information on customizing other woocommerce sections and pages, see the following additional articles: Woocommerce how to add images to products woocommerce checkout error messages customize woocommerce templates, please tell us how to use our article to customize and manage woocommerce related products. If you have any questions, please let us know in the \

Author:

Leave a Reply

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