I've moved the Stock.PHP and Price.PHP files from Templates into my theme WooCommerce -> Single Product folder. Now, I've tried to move this line of code from Stock.PHP into Price.PHP:
<p class="stock <?php echo esc_attr( $class ); ?>"><?php echo wp_kses_post( $availability ); ?></p>
This is my Stock.PHP file now.
<?php
/**
* Single Product stock.
* #version 3.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<!-- <p class="stock <?php echo esc_attr( $class ); ?>"><?php echo wp_kses_post( $availability ); ?></p> -->
And this is my Price.PHP file.
<?php
/**
* Single Product Price
* #version 3.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
?>
<p class="price"><?php echo $product->get_price_html(); ?></p>
<p class="stock <?php echo esc_attr( $class ); ?>"><?php echo wp_kses_post( $availability ); ?></p>
But for no reason, the Stock is not getting the esc_attr value and the availability of the product. How come this paragraph does get the class and the availability inside the Stock file but not inside the Price file?
Thanks,
Lucian
Related
I have a client who wants to do some customization in woo-commerce theme. I did many of the changes but now i am stuck at something that i want help with.
So the current theme products look like this here is the link https://www.wpselected.com/grotte/product-category/men/shoes-briefcases-men/?shop_layout=3col
and he wants to it to look like this, which is another themes product view
Here is the link http://negan.la-studioweb.com/
The add to cart button appears on hover on the price tag. and there is a wish-list button at the right corner
Here is the PHP code of current theme of content-product.php file
<?php
/**
* The template for displaying product content within loops
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 3.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product, $post;
// Ensure visibility
if ( ! $product || ! $product->is_visible() ) {
return;
}
?>
<li <?php post_class(); ?>>
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
<div class="brnhmbx-hover-group-container">
<a href="<?php esc_url( the_permalink() ); ?>">
<?php
/**
* woocommerce_before_shop_loop_item_title hook
*
* #hooked woocommerce_show_product_loop_sale_flash - 10
* #hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
?></a>
<div class="brnhmbx-hover-group">
<?php if ( shortcode_exists( 'yith_wcwl_add_to_wishlist' ) ) { echo do_shortcode( '[yith_wcwl_add_to_wishlist]' ); } ?>
<div class="brnhmbx-product-id"><?php echo get_the_ID(); ?></div>
<?php if ( function_exists( 'yith_wcqv_init' ) && get_option( 'yith-wcqv-enable' ) == 'yes' ) { ?><div class="brnhmbx-button ico-view"><i class="fa fa-search"></i></div><?php } ?>
<?php if ( get_theme_mod( 'brnhmbx_enableBFM', 1 ) ) {
if ( shortcode_exists( 'yith_wcwl_add_to_wishlist' ) || ( function_exists( 'yith_wcqv_init' ) && get_option( 'yith-wcqv-enable' ) == 'yes' ) ) { ?>
<div class="brnhmbx-button ico-gift brnhmbx-bfm"><i class="fa fa-gift"></i></div>
<?php } else { ?>
<div class="brnhmbx-button b170 clearfix ico-gift brnhmbx-bfm"><div><?php echo esc_attr( get_theme_mod( 'brnhmbx_tra_BFM_Header', 'BUY FOR ME' ) ); ?></div><i class="fa fa-gift"></i></div>
<?php }
} ?>
<?php if ( get_theme_mod( 'brnhmbx_enableCatalogMode', 0 ) ) { ?>
<div class="brnhmbx-button b170 ico-add-to-cart"><div><?php echo esc_attr( get_theme_mod( 'brnhmbx_catalogButtonText', 'VIEW PRODUCT' ) ); ?></div><div style="display: none;"><?php echo get_the_ID(); ?></div><i class="fa fa-angle-right"></i></div>
<?php } else {
if ( !in_array( $product->get_type(), array( 'variable', 'grouped', 'external' ) ) && $product->is_purchasable() && $product->is_in_stock() ) { ?>
<button type="submit" data-quantity="1" data-product_sku="<?php echo esc_attr( $product->get_sku() ); ?>" data-product_id="<?php echo esc_attr( $product->get_id() ); ?>" class="add_to_cart_button product_type_simple ttbutton secondary add-to-cart-grid single_add_to_cart_button button alt brnhmbx-button b170 ajax_add_to_cart"><span><?php echo wp_kses_post( $product->single_add_to_cart_text() ); ?></span></button>
<?php } else { ?>
<div class="brnhmbx-button b170 ico-add-to-cart"><div><?php echo wp_kses_post( $product->add_to_cart_text() ); ?></div><div style="display: none;"><?php echo get_the_ID(); ?></div><i class="fa fa-angle-right"></i></div>
<?php }
} ?>
</div>
</div>
<h3><?php the_title(); ?></h3>
<div class="brnhmbx-product-cat"><?php echo wc_get_product_category_list( $product->get_id() ); ?></div>
<?php
/**
* woocommerce_shop_loop_item_title hook
*
* #hooked woocommerce_template_loop_product_title - 10
*/
//'woocommerce_shop_loop_item_title' hook has been removed.
/**
* woocommerce_after_shop_loop_item_title hook
*
* #hooked woocommerce_template_loop_rating - 5
* #hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<div class="brnhmbx-summary-outer">
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ); ?>
<div class="brnhmbx-hover-group-list-top-margin"></div>
<div class="brnhmbx-hover-group-list">
<?php if ( shortcode_exists( 'yith_wcwl_add_to_wishlist' ) ) { echo do_shortcode( '[yith_wcwl_add_to_wishlist]' ); } ?>
<div class="brnhmbx-product-id"><?php echo get_the_ID(); ?></div>
<?php if ( function_exists( 'yith_wcqv_init' ) && get_option( 'yith-wcqv-enable' ) == 'yes' ) { ?><div class="brnhmbx-button ico-view"><i class="fa fa-search"></i></div><?php } ?>
<?php if ( get_theme_mod( 'brnhmbx_enableBFM', 1 ) ) {
if ( shortcode_exists( 'yith_wcwl_add_to_wishlist' ) || ( function_exists( 'yith_wcqv_init' ) && get_option( 'yith-wcqv-enable' ) == 'yes' ) ) { ?>
<div class="brnhmbx-button ico-gift brnhmbx-bfm"><i class="fa fa-gift"></i></div>
<?php } else { ?>
<div class="brnhmbx-button b170 clearfix ico-gift brnhmbx-bfm"><div><?php echo esc_attr( get_theme_mod( 'brnhmbx_tra_BFM_Header', 'BUY FOR ME' ) ); ?></div><i class="fa fa-gift"></i></div>
<?php }
} ?>
<?php if ( get_theme_mod( 'brnhmbx_enableCatalogMode', 0 ) ) { ?>
<div class="brnhmbx-button b170 ico-add-to-cart"><div><?php echo esc_attr( get_theme_mod( 'brnhmbx_catalogButtonText', 'VIEW PRODUCT' ) ); ?></div><div style="display: none;"><?php echo get_the_ID(); ?></div><i class="fa fa-angle-right"></i></div>
<?php } else {
if ( !in_array( $product->get_type(), array( 'variable', 'grouped', 'external' ) ) && $product->is_purchasable() && $product->is_in_stock() ) { ?>
<button type="submit" data-quantity="1" data-product_sku="<?php echo esc_attr( $product->get_sku() ); ?>" data-product_id="<?php echo esc_attr( $product->get_id() ); ?>" class="add_to_cart_button product_type_simple ttbutton secondary add-to-cart-grid single_add_to_cart_button button alt brnhmbx-button b170 ajax_add_to_cart"><span><?php echo wp_kses_post( $product->single_add_to_cart_text() ); ?></span></button>
<?php } else { ?>
<div class="brnhmbx-button b170 ico-add-to-cart"><div><?php echo wp_kses_post( $product->add_to_cart_text() ); ?></div><div style="display: none;"><?php echo get_the_ID(); ?></div><i class="fa fa-angle-right"></i></div>
<?php }
} ?>
</div>
</div>
<?php
/**
* woocommerce_after_shop_loop_item hook
*
* #hooked woocommerce_template_loop_add_to_cart - 10
*/
//'woocommerce_after_shop_loop_item' hook has been removed.
?>
</li>
As a general note - make sure that you're using a child theme before making any changes to template files. More information on child themes here (wpmudev)
Move the yith_wcwl_add_to_wishlist shortcode line out of the .brnhmbx-hover-group-list, and place it just before that div.
<div class="brnhmbx-hover-group-container">
<a href="<?php esc_url( the_permalink() ); ?>">
<?php
/**
* woocommerce_before_shop_loop_item_title hook
*
* #hooked woocommerce_show_product_loop_sale_flash - 10
* #hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
?></a>
<?php if ( shortcode_exists( 'yith_wcwl_add_to_wishlist' ) ) { echo do_shortcode( '[yith_wcwl_add_to_wishlist]' ); } ?>
<div class="brnhmbx-hover-group">
After this, you can adjust the styling via CSS - set the box to relative positioning and then add the appropriate spacing
.yith-wcwl-add-to-wishlist {
display: block;
position: absolute;
top: 20px !important;
right: 10px;
}
Similar thing for the 'Add to Cart' button, move this to after the hover box div
<?php if ( get_theme_mod( 'brnhmbx_enableCatalogMode', 0 ) ) { ?>
<div class="brnhmbx-button b170 ico-add-to-cart"><div><?php echo esc_attr( get_theme_mod( 'brnhmbx_catalogButtonText', 'VIEW PRODUCT' ) ); ?></div><div style="display: none;"><?php echo get_the_ID(); ?></div><i class="fa fa-angle-right"></i></div>
<?php } else {
if ( !in_array( $product->get_type(), array( 'variable', 'grouped', 'external' ) ) && $product->is_purchasable() && $product->is_in_stock() ) { ?>
<button type="submit" data-quantity="1" data-product_sku="<?php echo esc_attr( $product->get_sku() ); ?>" data-product_id="<?php echo esc_attr( $product->get_id() ); ?>" class="add_to_cart_button product_type_simple ttbutton secondary add-to-cart-grid single_add_to_cart_button button alt brnhmbx-button b170 ajax_add_to_cart"><span><?php echo wp_kses_post( $product->single_add_to_cart_text() ); ?></span></button>
<?php } else { ?>
<div class="brnhmbx-button b170 ico-add-to-cart"><div><?php echo wp_kses_post( $product->add_to_cart_text() ); ?></div><div style="display: none;"><?php echo get_the_ID(); ?></div><i class="fa fa-angle-right"></i></div>
<?php }
} ?>
and then style the css to make a similar button.
Some general tips:
When working with a theme that uses a combination of shortcodes (step 1) and theme functions (step 2) use your browser inspector to find out what code is generated and find where that fits into the theme. (For example, the wishlist is just a shortcode, but you can move that line to move where it appears.)
Try a combination of changes with CSS and the template - most some themes are 80% there and just require a few tweaks (like this one) others you'll need to put a lot more together.
as per title mention, right now the minicart is showing total based on the total quantity of the products, but not product name (ID). I assume it should be changed under "mini-cart.php" (correct me if I'm wrong). Can anyone tell me how and where to change this code? Thanks
refer here: https://shop.cheesang.com/wp-content/uploads/2019/09/sample.jpg
<?php
/**
* Mini-cart
*
* Contains the markup for the mini-cart, used by the cart widget.
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/mini-cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php do_action( 'woocommerce_before_mini_cart' ); ?>
<ul class="cart_list products-list product_list_widget <?php echo $args['list_class']; ?>">
<?php if ( ! WC()->cart->is_empty() ) : ?>
<?php
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key );
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
$product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
?>
<li>
<?php if ( ! $_product->is_visible() ) : ?>
<?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . ' '; ?>
<?php else : ?>
<a class="title" href="<?php echo esc_url( $_product->get_permalink( $cart_item ) ); ?>">
<?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . ' '; ?>
</a>
<?php endif; ?>
<?php echo WC()->cart->get_item_data( $cart_item ); ?>
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
<?php echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<i class="fa fa-times-circle"></i>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'snssimen' ) ), $cart_item_key ); ?>
</li>
<?php
}
}
?>
<?php else : ?>
<li class="empty"><?php _e( 'No products in the cart.', 'snssimen' ); ?></li>
<?php endif; ?>
</ul><!-- end product list -->
<?php if ( sizeof( WC()->cart->get_cart() ) > 0 ) : ?>
<p class="total"><?php _e( 'Total', 'snssimen' ); ?>: <strong><?php echo WC()->cart->get_cart_subtotal(); ?></strong></p>
<?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
<p class="buttons">
<?php _e( 'Go to Cart', 'snssimen' ); ?>
<?php _e( 'Checkout', 'snssimen' ); ?>
</p>
<span style="display:none" class="sns-cart-number">
<?php echo sizeof( WC()->cart->get_cart() ) ?>
<?php //echo $woocommerce->cart->cart_contents_count; ?>
</span>
<?php endif; ?>
<?php do_action( 'woocommerce_after_mini_cart' ); ?>
add this code in functions.php file
//This function will display total qty ni mini-cart
function filter__woocommerce_add_to_cart_fragments($fragments) {
ob_start(); ?>
<div class="number bold">
<?php echo sprintf( '%d', WC()->cart->cart_contents_count ); ?>
</div>
<?php
$fragments['#minicart .number'] = ob_get_clean();
return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'filter__woocommerce_add_to_cart_fragments' );
And to show mini-cart in header add this code in header.php file
<div class="mini-cart">
<a id="minicart" href="<?php echo WC()->cart->get_cart_url(); ?>" class="cart icon red relative">
<div class="number boldd">
<?php echo sprintf('%d', WC()->cart->cart_contents_count); ?>
</div>
<div id="cartcontents">
<div class="widget_shopping_cart_content">
<?php woocommerce_mini_cart(); ?>
</div>
</div>
</a>
</div>
I'm using WooCommerce with Flatsome Theme.
I want to add a subtitle to my products.
I installed the WooCommerce Product Subtitle plugin and I see the subtitles only at the shop page, but NOT in the single product page.
I was looking much around the internet but not success.
In the plugin area, I see this help offer:
F.A.Q.s
1.Subtitle not visible in single product page?
This issue might be with the theme which you are using
Please do make sure that your theme has woocommerce_single_product_summary filter in the below files
woocommerce_single_product_summary filter file list :
your-theme/woocommerce/content-product.php
What do I have to do? Here is the page:
<?php
/**
* The template for displaying product content within loops
*/
defined( 'ABSPATH' ) || exit;
global $product;
// Ensure visibility.
if ( empty( $product ) || ! $product->is_visible() ) {
return;
}
// Check stock status.
$out_of_stock = get_post_meta( $post->ID, '_stock_status', true ) == 'outofstock';
// Extra post classes.
$classes = array();
$classes[] = 'product-small';
$classes[] = 'col';
$classes[] = 'has-hover';
if ( $out_of_stock ) $classes[] = 'out-of-stock';
?>
<div <?php fl_woocommerce_version_check( '3.4.0' ) ? wc_product_class( $classes ) : post_class( $classes ); ?>>
<div class="col-inner">
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
<div class="product-small box <?php echo flatsome_product_box_class(); ?>">
<div class="box-image">
<div class="<?php echo flatsome_product_box_image_class(); ?>">
<a href="<?php echo get_the_permalink(); ?>">
<?php
/**
*
* #hooked woocommerce_get_alt_product_thumbnail - 11
* #hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'flatsome_woocommerce_shop_loop_images' );
?>
</a>
</div>
<div class="image-tools is-small top right show-on-hover">
<?php do_action( 'flatsome_product_box_tools_top' ); ?>
</div>
<div class="image-tools is-small hide-for-small bottom left show-on-hover">
<?php do_action( 'flatsome_product_box_tools_bottom' ); ?>
</div>
<div class="image-tools <?php echo flatsome_product_box_actions_class(); ?>">
<?php do_action( 'flatsome_product_box_actions' ); ?>
</div>
<?php if ( $out_of_stock ) { ?><div class="out-of-stock-label"><?php _e( 'Out of stock', 'woocommerce' ); ?></div><?php } ?>
</div><!-- box-image -->
<div class="box-text <?php echo flatsome_product_box_text_class(); ?>">
<?php
do_action( 'woocommerce_before_shop_loop_item_title' );
echo '<div class="title-wrapper">';
do_action( 'woocommerce_shop_loop_item_title' );
echo '</div>';
echo '<div class="price-wrapper">';
do_action( 'woocommerce_after_shop_loop_item_title' );
echo '</div>';
do_action( 'flatsome_product_box_after' );
?>
</div><!-- box-text -->
</div><!-- box -->
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
</div><!-- .col-inner -->
</div><!-- col -->
maybe the subtitle is not hooked anywhere in the single product page.
Can you try to add this snippet to your theme's functions.php file?
add_action('woocommerce_shop_loop_item_title', 'fc_single_product_subtitle');
function fc_single_product_subtitle() {
$subtitle = get_product_subtitle( get_the_ID() );
if( ! empty( $subtitle ) ) echo $subtitle;
}
Let me know and good luck!
finelly, after lot of hours...
my site using with Elementor pro, so i just edit the tamplate of single page product from the plugin:
Dashboard > Elementor Tamplates (can show diffrent on some versions).
click edit to my producte page tamplate.
when the elementor builder load my tamplate producte page i just insert shortcode widget and use shortcode [wc-ps] to use with my subtitles data.
I have no idea of php so I was wondering if I can get help from you guys.
So basically this is my code for woocommerce minicart.
Right now when I click on a single item to buy twice the cart counter stays on 1, when instead I obviously want 2 as it is the total.
I am aware of the things saying here, but I can't seem to find where to put the code. I tried everything and I can't make those totals to show up.
If someone can tell me which part exactly should be changed I would very much appreciate it. Thanks in advance!
<?php
/**
* Mini-cart
*
* Contains the markup for the mini-cart, used by the cart widget.
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/mini-cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php do_action( 'woocommerce_before_mini_cart' ); ?>
<ul class="cart_list products-list product_list_widget <?php echo $args['list_class']; ?>">
<?php if ( ! WC()->cart->is_empty() ) : ?>
<?php
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key );
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
$product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
?>
<li>
<?php if ( ! $_product->is_visible() ) : ?>
<?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . ' '; ?>
<?php else : ?>
<a class="title" href="<?php echo esc_url( $_product->get_permalink( $cart_item ) ); ?>">
<?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . ' '; ?>
</a>
<?php endif; ?>
<?php echo WC()->cart->get_item_data( $cart_item ); ?>
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
<?php echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<i class="fa fa-times-circle"></i>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'snssimen' ) ), $cart_item_key ); ?>
</li>
<?php
}
}
?>
<?php else : ?>
<li class="empty"><?php _e( 'No products in the cart.', 'snssimen' ); ?></li>
<?php endif; ?>
</ul><!-- end product list -->
<?php if ( sizeof( WC()->cart->get_cart() ) > 0 ) : ?>
<p class="total"><?php _e( 'Total', 'snssimen' ); ?>: <strong><?php echo WC()->cart->get_cart_subtotal(); ?></strong></p>
<?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
<p class="buttons">
<?php _e( 'Go to Cart', 'snssimen' ); ?>
<?php _e( 'Checkout', 'snssimen' ); ?>
</p>
<span style="display:none" class="sns-cart-number">
<?php echo sizeof( WC()->cart->get_cart() ) ?>
<?php //echo $woocommerce->cart->cart_contents_count; ?>
</span>
<?php endif; ?>
<?php do_action( 'woocommerce_after_mini_cart' ); ?>
I am using Wordpress with woocommerce and trying to set up some variable products. But variable products show the "In Stock" messages directly below the input/select field. I want it to be shown below the "Add to cart" button.
I am using a child theme for the files, simple.php, variable.php and variation.php.
Feel free to look at the picture to see what I want to do.
http://art-wood.de/instock-move.png
Currently my variable.php looks like this:
<?php
/**
* Variable product add to cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/variable.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
$attribute_keys = array_keys( $attributes );
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo htmlspecialchars( json_encode( $available_variations ) ) ?>">
<?php do_action( 'woocommerce_before_variations_form' ); ?>
<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
<div class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></div>
<?php else : ?>
<span class="variations" cellspacing="0">
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<label class="label" for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label>
<div class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __( 'Clear', 'woocommerce' ) . '</a>' ) : '';
?>
</div>
<?php endforeach;?>
</span>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_variation_wrap">
/**
* woocommerce_before_single_variation Hook.
*/
do_action( 'woocommerce_before_single_variation' );
/**
* woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
* #since 2.4.0
* #hooked woocommerce_single_variation - 10 Empty div for variation data.
* #hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
/**
* woocommerce_after_single_variation Hook.
*/
do_action( 'woocommerce_after_single_variation' );
?>
</div>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
<?php endif; ?>
<?php do_action( 'woocommerce_after_variations_form' ); ?>
</form>
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
Does somebody know how to move the message down below the Add to cart button? This would be amazing! May its a simple add to the functions.php maybe its a switch in the variable.php... I don't know that. Otherwise I wouldn't ask :)
I found the solution by myself. Maybe its useful for someone so here it is ;)
Simply add this to your functions.php
remove_action( 'woocommerce_single_variation' , 'woocommerce_single_variation', 10);
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 20 );