How to deacivate related products on wordpress? - wordpress

I am working on wordpress,the plugins are :woocommerce,datafeedr api,and datefeedr product sets,I added some products from datafeedr also in woocommerce,now I want to deactivate the related product temporarily,I don t went to remove them.

remove_action(
'woocommerce_after_single_product_summary',
'woocommerce_output_related_products',
20
);
If that didn't work, remove it and use this in functions.php:
add_filter(
'woocommerce_related_products_args',
'_remove_related_products',
10
);
function _remove_related_products( $args ) {
return array();
}
I hope this one work, if didn't, you change 10 to 20, 30 or ... until it works, I hope.

Related

Move "Add to Cart" form below product description

I want to move only add to cart form below products description. To explain better:
Found this function, but it moves this at top of product under description. So some part of function is not right. Can someone to help me?
add_action( 'woocommerce_single_product_summary',
'customizing_variable_products', 1 );
function customizing_variable_products() {
global $product;
if( ! $product->is_type( 'variable' ) ) return;
remove_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart', 15 );
}
You have to copy / paste all the woocommerce templates into your current template folder.
This way, the woocommerce theming isn't gonna take it's own templating but will take the one you pasted instead.
Then, you'll just have to find, where, in the template files where is printed the options, and where is printed the add to cart button. You'll be then able to switch the code sa that it makes what you need.
here is the doc about how overriding templates files.

wc_print_notices is not displaying any messages in woocommerce pages?

I have used default woocommerce templates for shop, cart and single page.
I have not removed any hooks either but also I am not getting any message.
Any Idea?
add_action( 'woocommerce_before_single_product', 'Cusotm_wc_print_notices', 10 );
function Cusotm_wc_print_notices()
{
echo 'Hook is working fine';
}
I am getting this message 'Hook is working fine' but not wc_print_notices();.
I'm not really sure what is the problem. Your question needs further details. With that said, can you try adding this code to your functions.php of your current theme.
add_action( 'template_redirect', 'test' );
function test() {
wc_add_notice( __( 'Sorry there was a problem.', 'woocommerce' ), 'error' );
}
Let me know if it does something.
UPDATE
If you have something like this:
add_action( 'woocommerce_before_single_product', 'Cusotm_wc_print_notices', 10 );
function Cusotm_wc_print_notices()
{
$notices = WC()->session->get('wc_notices');
print_r($notices);
}
it will not work because $notices will be empty once wc_print_notices() is called.
try changing priority and you will get something. Should be something like this:
add_action( 'woocommerce_before_single_product', 'Cusotm_wc_print_notices', 9 );
use priority below 10. Because WooCommerce is using 10.
add_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );

remove_action on related products is not working with woocommerce hook

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
I have this line in my functions.php file. I got these hooks from the content-single-product.php file. However, the related products on my single product page still exists.
I don't want to remove the functionality entirely, I duped their $args to do my own query.
Updated
function remove_woo_relate_products(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
}
add_action('init', 'remove_woo_relate_products', 10);
I tried to write a function to achieve my goal, but the related products from the do_action is still present. I can only think of CSS to do what I need, but I shouldn't have to rely on this.
Also, just for the sake of showing this, this is what's in the content-single.product.php file:
<?php
/**
* woocommerce_after_single_product_summary hook.
*
* #hooked woocommerce_output_product_data_tabs - 10
* #hooked woocommerce_upsell_display - 15
* #hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
As LoicTheAztec correctly pointed out, your code is working fine. We tested it. The related products were removed but the upsell products were still there.
We tested using storefront theme.
function remove_woo_relate_products(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
remove_action( 'woocommerce_after_single_product_summary', 'storefront_upsell_display', 15 );
}
add_action('init', 'remove_woo_relate_products', 10);
You can see that storefront_upsell_display is calling the woocommerce_upsell_display
function storefront_upsell_display() {
woocommerce_upsell_display( -1, 3 );
}
So in this code, we have removed the theme's action for upsell. In the same logic, there is a possibility that related products function may be called in your theme. If this is the case you can remove the corresponding action for that.
Note: Make sure the code is in your current theme's functions.php

How To Move Product Variation Descriptions in WooCommerce

I'd like to move my product's variation descriptions in Woocommerce beneath the add to cart button, and I can't find what hook I'm supposed to use. These are the variation's custom descriptions that load on selection in AJAX.
I'm able to hook another custom function beneath the add to cart button. So I think my problem is not knowing the name of the hook and/or if it's a hook versus a filter. I think it's either woocommerce_before_single_variation or woocommerce_before_add_to_cart_button.
Here's several attempts I've tried before with no luck in functions.php:
remove_action( 'woocommerce_after_single_variation','woocommerce_single_product_summary', 20 );
add_action( 'woocommerce_after_single_variation', 'woocommerce_single_product_summary', 9 );
//try #2
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_after_add_to_cart_button', 'woocommerce_single_variation', 35);
Thank you!
The functionality I was looking for is included in WooCommerce 2.4 as a default but is not done on a hook. It's added by jQuery updating a div instead - which I found in woocommerce/js/assets/frontend/add-to-cart-variation.js. So I moved the div's location instead:
add_action ('woocommerce_after_single_variation', 'move_descriptions', 50);
function move_descriptions() {
?>
<div class="woocommerce-variation-description" style="border: 1px solid transparent; height: auto;"></div>
<?php
}
I think this will do,
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_after_add_to_cart_form', 'woocommerce_template_single_excerpt');
Only move Short description if product is variable
add_action('wp_head', 'move_short_desc_for_varition');
function move_short_desc_for_varition() {
#
global $post;
$product = get_product( $post->ID );
if( $product->is_type( 'variable' ) ){
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_after_add_to_cart_form', 'woocommerce_template_single_excerpt');
}
}
The problem is in the priority of the remove hook.
I give you an example (this work for me):
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 15 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
Pay attention and try with differents priorities.

Hiding prices in WooCommerce for a set of products

In our Woocommerce products, we have two types of products.
Products imported through script from a external XML url file.
Products added as usual through woo admin interface.
We have added a meta field to identify these imported products.
What is the best method to hide prices ONLY for these imported products?
I have tried by removing some woocommerce actions, but its affects all woo products.
I have tried by removing some woocommerce actions, but its affects all woo products.
Then you need conditional logic. This should get rid of the price display in the loop.
EDIT As pointed out in the comments, once you remove the action it is permanently removed for all ensuing products. So in light of that I have added an else statement that resolves this issue.
function so_32584641_remove_price_from_loop(){
global $product;
if( 'mycbgenie' == get_post_meta( $product->id, '_mycbgenie_managed_by', true ) ){
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' );
} else {
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' );
}
}
add_action( 'woocommerce_before_shop_loop_item', 'so_32584641_remove_price_from_loop' );
and this should remove it from the single product page:
function so_32584641_remove_price_from_single(){
global $product;
$your_meta = get_post_meta( $product->id, '_your_meta_key', true );
if( 'mycbgenie' == $your_meta ){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
}
}
add_action( 'woocommerce_before_single_product', 'so_32584641_remove_price_from_single' );

Resources