Remove simple product from product data woocommerce - wordpress

How can we remove simple product and variable product from product data dropdown in woocommerce.

You can use product_type_selector filter hook and unset to remove simple product type. check below code. code will go into the active theme functions.php file.
add_filter( 'product_type_selector', 'remove_product_types_simple' );
function remove_product_types_simple( $types ){
unset( $types['simple'] );
return $types;
}

Related

Show custom text block on product page only if a product is out of stock with backorder enabled

i have a wordpress site with woocommerce and flatsome theme. The theme give the possibility to add easily a custom html text before or after the add to cart button.
I would like that the html text show up only for out of stock with backorder enabled products, for single and variables products.
the theme have this code
// Add HTML after Add to Cart button
function flatsome_after_add_to_cart_html(){
echo do_shortcode(get_theme_mod('html_after_add_to_cart'));
}
add_action( 'woocommerce_single_product_summary', 'flatsome_after_add_to_cart_html', 30);
any help is appreciated
You can likely do that with just an additional couple of checks in your function. Before echoing the content - check the $product like this:
function flatsome_after_add_to_cart_html(){
global $product;
if( ! $product->is_in_stock() && $product->backorders_allowed() ){
echo do_shortcode(get_theme_mod('html_after_add_to_cart'));
}
}
add_action( 'woocommerce_single_product_summary', 'flatsome_after_add_to_cart_html', 30);

How to customize product category widget in woocommerce

i can not understand How to customize product category widget in woocommerce Version 3.0.7 (not using any plugin).
like that..
You can customize the arguments of product category widget by following code in functions.php,
add_filter( 'woocommerce_product_categories_widget_args', 'widget_arguments' );
function widget_arguments( $args ) {
$args['exclude'] = array('12','14');
return $args;
}
Here is the argument list from default file.
http://hookr.io/plugins/woocommerce/3.0.6/files/includes-widgets-class-wc-widget-product-categories/

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' );

woocommerce get product id when product is add to cart

I need to do extra step in the backend when a product is add to cart.
I need to get the product ID juste after it's add to the cart.
I use the woocommerce hook woocommerce_add_to_cart
add_action('woocommerce_add_to_cart', 'attach_item');
function attach_item() {
// I need to have the product id here.
}
I tried many way to get the ID but nothing work.
Any idea ...
Today I also get the same problem but I got the solution.
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart',10,2 );
function woo_custom_add_to_cart( $cart_item_data,$productId ) {
var_dump($productId);
}
At the time of writing this, the hook is actually called from WooCommerce like so: (source)
do_action( 'woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data );
Add your custom method like so:
add_action('woocommerce_add_to_cart', function($cartItemKey, $productId) {
// do sth with $productId
}, 10, 2);

Woocommerce customize the product name in the cart and order pages

Actually, I already got hook to customize the price in the cart page and all other page.
This is the hook to customize the product price
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
}
}
Actually, I am using woocommerce plugin. I want a hook to customize the product name displayed in the cart page and all other pages next to cart page.
I want to customize the Product name , i want to add the some static attributes to product name displayed in the cart page, order page ,order details page and all the pages next to cart page.
Thanks in advance
I wanted to share this as I managed to figure out something for my needs. (I only ever have a single item in the order as I've customised WooCommerce for holiday bookings.)
<?php
add_action( 'woocommerce_product_title', 'add_custom_name' );
function add_custom_name( $title ) {
return 'test name';
}
?>
Hopefully someone can elaborate on this further or take what has been done with the custom price code an properly re-purpose it for product names.

Resources