Remove Variations from Cart Page - woocommerce

On my website I am using woocommerce with product variations on. If someone adds a product to the cart with the variations on it will show what variations they chose in the cart page, I don't want that because it messes up the spacing of the cart table. I want to remove this from the css code so that only the product name is remaining and not all the additional variations but I don't know where to start. If this is not descriptive enough please go to my website and add a product to the cart and you will see what I mean.

in my opinion as a buyer I would like to see what kind of variation I'm ordering, but if you really want to do that:
go to your woocommerce templates folder inside your chosen theme, then inside the cart folder you'll find cart-item-data.php either comment everything between line 21-28 or remove it entirely.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<!-- <dl class="variation">
<?php foreach ( $item_data as $data ) : ?>
<div>
<dt class="variation-<?php echo sanitize_html_class( $data['key'] ); ?>"><?php echo wp_kses_post( $data['key'] ); ?>:</dt>
<dd class="variation-<?php echo sanitize_html_class( $data['key'] ); ?>"><?php echo wp_kses_post( wpautop( $data['display'] ) ); ?></dd>
</div>
<?php endforeach; ?>
</dl>-->
if you prefer to hide it with CSS, then you can use this piece of css:
.woocommerce-cart td.product-name dl.variation dt {
display: none;
}
.woocommerce-checkout td.product-name dl.variation dt {
display: none;
}

Related

get variable product attributes in cart page woocommerce

I want to display the attributes selected by the user on the cart page in WooCommerce
I tried to get attributes from the variable product but could not
I was able to fix this problem as follows
if ($_product->get_attributes()){
foreach ($_product->get_attributes() as $key => $val) { ?>
<p><?= wc_attribute_label($key) ?> : <span> <?= $val ?></span></p>
<?php }
}?>
you can get attributes from $_product

How to display posts with plugin (advanced custom fields) field groups?

I have a php/wordpress code (present inside abc.php file) as shown below which displays images of particular size.
php/wordpress (inside abc.php file):
<ul id="list-thumbs" class="list-grid">
<?php
while ( have_posts() ) : the_post();
?>
<li class="list-grid__thumb shows-grid__item">
<a class="list-grid__img-link" href="<?php echo esc_url( get_the_permalink() ); ?>" tabindex="0">
<?php if ( has_post_thumbnail() ) { ?>
<?php
$image_id = get_post_thumbnail_id( get_the_ID() );
WORLD\Images\the_img_fit_figure( $image_id, 'list-grid__image', '(min-width: 450px) 50vw, 70vw', false ); ?>
<?php } ?>
</a>
</li>
<?php endwhile; ?>
</ul>
The code above displays around 30-40 images from top to bottom with 4 images in one row.
(a) All of those images are featured image in wordpress associated with a post of post_type hello-world
(b) Every post has two fields, Row View (in_row_view) and Column View (in_column_view) coming from Advanced Custom Fields plug in. I am not sure if we can call those two fields as custom fields.
(c) Row View and Column View both are switch which can be enabled to Yes or No. By default, it is set to No.
(d) For Row View, I am using:
if(get_field('in_row_view' ) == '1'){ }
For Column View, I am using:
if( get_field('in_column_view' ) == '1'){ }
What I want to achieve is I want to display those posts which have Row View switch enabled to Yes.
Problem Statement:
I am wondering what changes I need to make in the php/wordpress code above so that it displays only those posts which have Row View switch enabled to Yes.
Probably I need to integrate this code if(get_field('in_row_view' ) == '1'){ } in the php/wordpress code above.
Quick/Sloppy Solution:
<ul id="list-thumbs" class="list-grid">
<?php
while ( have_posts() ) : the_post();
// This will skip the loop
if(get_field('in_row_view' ) != '1') { continue; }
?>
<li class="list-grid__thumb shows-grid__item">
<a class="list-grid__img-link" href="<?php echo esc_url( get_the_permalink() ); ?>" tabindex="0">
<?php if ( has_post_thumbnail() ) { ?>
<?php
$image_id = get_post_thumbnail_id( get_the_ID() );
WORLD\Images\the_img_fit_figure( $image_id, 'list-grid__image', '(min-width: 450px) 50vw, 70vw', false ); ?>
<?php } ?>
</a>
</li>
<?php endwhile; ?>
</ul>
... the issue with the "Quick Solution" is that it will not render the desired "posts per page". The easier way is to include or exclude at the query level with meta_query ... this can be done by grabbing the query "in flight" with the pre_get_posts hook.
The More Elegant Solution
function pw_filter_query( $query ) {
// Your conditions for NOT applying the meta query ... use wp conditionals! :)
if( !$query->get('post_type') != 'your_post_type ) { return $query; }
$query->set('meta_key', 'ecpt_color');
$query->set('meta_value', 'green');
}
}
add_action('pre_get_posts', 'pw_filter_query', 9999);
Source Reference

How can I hide the price's inside the Cart for unregisterd users wordpress

Basically I have downloaded a plugin to hide price's for unregistered user's. The problem is if the customer clicks on "Add to Cart" button and they go at the Cart they can see the price. Is there any setting to disable prices on cart for unregisterd users or anything related to that?
Thank's in advance
simple way to do this is overwrite cart template and check if user is login then display. I show you the logic. I hope you know how to overwrite template. still brief I say you here.
This is to overwrite cart.
woocommerce/templates/cart/cart.php to
yourtheme/woocommerce/cart/cart.php
this is for check logic
<?php if(is_user_logged_in()){ ?>
<td class="product-price" data-title="<?php esc_attr_e( 'Price', 'woocommerce' ); ?>">
<?php
echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); // PHPCS: XSS ok.
?>
</td>
<?php } ?>
you also need to do same for label.

Wordpress Woocommerce: Single product page gallery of variations

The thing I need is variation to be changed on selected products when I click on image associated with it. The same way as displayed image changes clicking variation from dropdown (but vice versa). I spent days looking for solution, that must be so simple. Is it solvable with writing some code? I don’t want plugins like swatches. I am not born English speaker, so hope it’s understandable enough. Thanks for ANY kind of help.
Here:
http://obrazyzedreva.cekuj.net/produkt/svata-rodina/
Wordpress, Woocommerce, Customify template
This is how I solved it:
part of product-image.php
<div>
<div>
<?php
if( $product->is_type( 'variable' ) ){
?>
<div>
<div>
<strong>Vyberte si variantu:</strong>
</div>
<?php
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
echo '<div style="display:inline-block">';
echo '<img class="selector_'. $variation['variation_id'] .'" width="80" height="80" src=' . $variation['image']['url'] . ' style="margin-right:7px;">';
echo '</div>';
}
?>
</div>
<script type="text/javascript">
jQuery(function($){
<?php foreach ( $variations as $variation ) {
foreach($variation['attributes'] as $attributes) {
?>
$('.selector_<?php echo $variation['variation_id'] ?>').click(function(){
$('select[name="attribute_model-vyrobni-cislo"] option[value="<?php echo $attributes ?>"]').attr("selected","selected").trigger('change');
});
<?php
}
}
?>
});
</script>
<?php
}
?>
</div>
</div>

Changing header cart text in Storefront

I would like to edit the text in the header mini cart in Storefront theme:
'X items'
to just :
'X'
http://demo.woothemes.com/storefront/
Where can I access this? Can't find it anywhere in storefront or woocommerce files. I can see hook in header.php:
storefront_header_cart
but can't find any function for this in other files?
I would like to remove the dropdown when you hover over it too. Where can I change this?
that functionality is handled by storefront_cart_link function...
you can override the function... open functions.php... look for require get_template_directory() . '/inc/init.php';
right above it, paste this code...
if ( ! function_exists( 'storefront_cart_link' ) ) {
function storefront_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
<?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo wp_kses_data( sprintf( '%d', WC()->cart->get_cart_contents_count() ) );?></span>
</a>
<?php
}
}
storefront_cart_link is loaded with this call require get_template_directory() . '/inc/init.php';. So above will load first, making it not create that function anymore with the call of require get_template_directory() . '/inc/init.php';.
This will do the trick.. but better use child theme... you can just paste directly the function above on the child theme's functions.php. functions.php on a child theme will load first than that of the parent, so making your function exist first.

Resources