In wordpress WooCommerce, when i add a Variation Product, variation is set only by Two colors,
Starwhite = 9000
Ivory = 15000
On the Single Product page, I get to see price mentioned twice, as shown in screenshots.
I want to retain the price defined in variation. Remove the other one.
The price which is not required is showing up under the div below
<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
<p class="price"><span class="amount">Rs.9,000.00</span>–<span class="amount">Rs.15,000.00</span></p>
<meta itemprop="price" content="9000" style="
/* display: none; */
">
<meta itemprop="priceCurrency" content="INR">
<link itemprop="availability" href="http://schema.org/InStock">
</div>
But when i mark it has display none or visibility hidden, the price from variation is also gone..
1st Color Variation settings:
2nd Color Variation settings:
Also, there are times when i use Simple Product on the website, so any changes suggested should not impact simple product settings.
If i have to make any changes in the code, what should be the code and under which php files should it be changes.
I believe the file you need to edit is "/single-product/price.php", you should have a copy of that file in your theme folder (/your-theme/woocommerce/single-product/price.php), if not you can copy it there from /wp-content/plugins/woocommerce/templates/
Change:
<p class="price"><?php echo $product->get_price_html(); ?></p>
To:
<?php if( $product->is_type( 'simple' ) ){ ?><p class="price"><?php echo $product->get_price_html(); ?></p><?php } ?>
That will make it only display the price for Simple Products. The other price display that changes when you select a different variation is set in /single-product/add-to-cart/variable.php so that will be unaffected.
Related
I'm looking to change heading tag (currently H5) for product categories displaying on home page. These categories are displayed on home page by using an element named ux_product_categories on Flatsome theme.
It seems to be a shortcode. So I looked at product_categories.php file in wp-content/themes/flatsome/inc/shortcodes.
Indeed, I found H5 heading tag, however, when I change it (by putting the modified file with the same path in child theme)... Nothing happens, product categories have still H5 heading tag.
What do I missed ?
Here's the code I changed (replacing "h5" by "p") :
<div class="box-text <?php echo implode(' ', $classes_text); ?>" <?php echo get_shortcode_inline_css($css_args); ?>>
<div class="box-text-inner">
<h5 class="uppercase header-title">
<?php echo $category->name; ?>
</h5>
I have below formatting for microdata and adding this on content-single-product.php WooCommerce template. Below is the code I am trying to add:
<div itemscope itemtype="http://schema.org/Product">
<meta itemprop="name" content="Product Name">
<div itemscope itemtype="http://schema.org/Offer">
<meta itemprop="sku" content="Product SKU">
<meta itemprop="price" content="Product Price" />
<meta itemprop="priceCurrency" content="Price Currency ex. INR" />
<meta itemprop="category" content="Category Name">
<meta itemprop="availability" content="http://schema.org/InStock" />
</div>
<div itemscope itemtype="http://schema.org/PriceSpecification">
<meta itemprop="minPrice" content="Special Price">
<meta itemprop="validFrom" content="Sale Start Date">
<meta itemprop="validThrough" content="Sale End Date">
</div>
<div itemscope itemtype="http://schema.org/Thing">
<meta itemprop="image" content="Product Image URL">
<meta itemprop="description" content="Product Description">
</div>
</div>
In this content-single-product.php template, I am adding some code below this line:
<div itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
I am using WooCommerce functions to fetch product details, but it returns HTML formatted values and I need non-formatted product values.
Here are the TAGs details:
1. Tags for Product Basic Details
Product Name:
<meta itemprop="name" content="Product Name">
Assign product name under CONTENT . This specifies the product title and will be shown to users during search.
Product SKU Code
<meta itemprop="sku" content="Product SKU">
Assign unique product code for your product.
Product URL:
<meta itemprop="url" content="Product URL">
This tag contain product page URL from your website. This may be like http://www.YourWebsiteName.com/ProductName.php
Product Category
<meta itemprop="category" content="Category Name">
Assign Category Name under which your product is listed on your website.
Product Picture
<meta itemprop="image" content="Product Image URL">
This tags contains product image url. You need to put your product image full url here.
For example: http://www.YourWebsite.com/images/product_image.png
Product Description
<meta itemprop="description" content="Product Description">
Include product detail here.
2. Tags for Price
Price Currency:
<meta itemprop="priceCurrency" content="INR" />
Mention your product currency here.
Product Sale Price:
<meta itemprop="price" content="Product Price" />
This tags will contain product sale price/mrp. This is actual price above which product is not available in market. The price should be a number without separators between thousands or spaces (e.g. '8.99').
Product Special Price:
<meta itemprop="minPrice" content="Special Price">
Provide discounted price, offer price or special price for the products. This is not mandatory but important to get top listing in search results. If left blank, system will assign value 0 automatically. The price should be a number without separators between thousands or spaces (e.g. '8.99').
Special Price Start Date:
<meta itemprop="validFrom" content="Sale Start Date">
If Discounted price is offered, mention special price start date in DD/MM/YYYY format. If blank, system will assign current date automatically.
Special Price End Date:
<meta itemprop="validThrough" content="Sale End Date">
If Discounted price is offered, mention special price end date in DD/MM/YYYY format. If blank, system will assign date after 30 days automatically.
Thanks.
You need to get the current Product object and for this you will use together get_the_id() WordPress function with wc_get_product() WooCommerce function this way:
$product = wc_get_product(get_the_ID()); // Getting the Product object from current post ID
With that $product object you can access to any raw data for the current product.
You can use all WC_Product class properties and magic properties using the arrow syntax:
echo $product->property_slug; // displays the product property (if is a string value)
(Here property_slug should be replaced by one of the properties listed in WC_Product class).
$product_id = $product->id;
$product_type = $product->product_type;
$product_post_object = $product->post; // see below
With the post property you can access to all post object properties (just as in wp_post table):
$product_slug = $product->post->post_name;
$product_title = $product->post->post_title;
$product_description = $product->post->post_content;
$product_short_description = $product->post->post_excerpt;
Then using WC_Product class methods, you will get the following:
$product_sku = $product->get_sku(); // or $product->sku
$product_url = $product->get_permalink();
// As a product can be in many categories (array)
$product_categories_array = get_the_terms( $product->id, 'product_cat' );
// The categories in a coma separated string
$product_categories_string = $product->get_categories();
To get the currency you will use dedicated function get_woocommerce_currency()
For the prices you will use related WC_product properties:
$product_price = $product->price;
$product_reg_price = $product->regular_price;
// Product Sale price
$product_sale_price = $product->sale_price;
// Scheduled Sale price dates (timestamps)
$product_sale_start_ts = get_post_meta($product->id, '_sale_price_dates_from', true);
$product_sale_end_ts = get_post_meta($product->id, '_sale_price_dates_to', true);
To format Product Scheduled Sale price dates in DD/MM/YYYY format, as they are stored in database as timestamps values, we will use PHP date() function this way:
$product_sale_start_ts = get_post_meta($product->id, '_sale_price_dates_from', true);
$product_sale_start_date = date('d/m/Y', $product_sale_start_ts);
$product_sale_end_ts = get_post_meta($product->id, '_sale_price_dates_to', true);
$product_sale_end_date = date('d/m/Y', $product_sale_end_ts);
You can also access to this product meta data using get_post_meta() WordPress function, for example to get the SKU you will use:
$product_sku = get_post_meta($product->id, '_sku', true);
For product image The dedicated function is get_the_post_thumbnail() function:
$product_image = get_the_post_thumbnail( $product_id, 'shop_single' );
But as a product can have or not an image, or even a gallery of images you should look at the code in woocommerce templates > single-product > product-image.php template…
On my WooCommerce checkout page, I am selling only one product. The checkout page is showing this product and there is ckeckbox next to it, to show the shipping details, when clicked. This is on the default form-checkout.php WooCommerce template.
I would like to have this ckeckbox always selected, to show billing details by default.
I have tried to set:
$checkout = 1;
With no luck so far. The radio button is displayed by the following hook:
<?php do_action( 'woocommerce_checkout_before_customer_details'); ?>
Any help letting me know how I can achieve this will be very helpful.
Thanks.
If you look to the code of checkout/form-shipping.php WooCommerce template, inside the <h3> tag, where the checkbox code is located, there is woocommerce_ship_to_different_address_checked hook that you can use to achieve that. Here is an extract of this code template, that shows it:
?>
<div class="woocommerce-shipping-fields">
<?php if ( true === WC()->cart->needs_shipping_address() ) : ?>
<h3 id="ship-to-different-address">
<label for="ship-to-different-address-checkbox" class="checkbox"><?php _e( 'Ship to a different address?', 'woocommerce' ); ?></label>
<input id="ship-to-different-address-checkbox" class="input-checkbox" <?php checked( apply_filters( 'woocommerce_ship_to_different_address_checked', 'shipping' === get_option( 'woocommerce_ship_to_destination' ) ? 1 : 0 ), 1 ); ?> type="checkbox" name="ship_to_different_address" value="1" />
</h3>
<div class="shipping_address">
So you can use this hook this way, to get this checkbox always selected and displays billing details:
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true');
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
hello I am trying to display the special price and discount percentage to the category page products. I have managed to do it on the actual product view but it still displays just the base price on the category page so without clicking into the product the user would not be aware a different price exists. I have added the following code to this file:
app/design/frontend/mytheme/default/template/catalog/price
above this
<?php // Display Discount percents start ?>
<?php if($_finalPrice < $_price): ?>
<?php $_savingPercent = 100 - round(($_finalPrice / $_price)*100); ?>
<p class="special-price yoursaving">
<span class="label"><?php echo $this->__('Your Saving:') ?></span>
<span class="price">
<?php echo $_savingPercent; ?>%
</span>
</p>
<?php endif; ?>
It works nicely for the product page view but i just need to figure how to display on the category pages with the special price also shown.
Any help appreciated thanks!
I am using magento 1.8.1 and i am trying to display discount percent with sell price on frontend.
with the help of this site discount
i am putting these code:
<?php // Discount percents output start ?>
<?php if($_finalPrice < $_price): ?>
<?php $_savePercent = 100 - round(($_finalPrice / $_price)*100); ?>
<p class="special-price yousave">
<span class="label"><?php echo $this->__('You Save:') ?></span>
<span class="price">
<?php echo $_savePercent; ?>%
</span>
</p>
<?php endif; ?>
in this page: app/design/frontend/yourpackage/yourtheme/template/catalog/product/price.phtml
but after that the result is showing as like this:
Now i am not able to find why "undefined" is showing here and how to remove this.
Please tell me how to remove this.
I seen in your question image you need this effect on product detail page so have to edit media.phtml
app\design\frontend\YOUR_PACKAGE\YOUR_THEME\default\template\catalog\product\view\media.phtml
And in that you have to do same coding to get this value. you can make wrapper class which is override to product image with some dynamic text over product image like as you want.
You can use css like in this page
I think its work...try in this way