Echo php product title - Wordpress/Woocommerce - php

I have a text that I want to dispay as a description on every single product page and I want to echo the product name in the fields.
Example: ''Buy this (product name) from our store. This is the best (product name) in the industry. By using this (product name) you save more.''
I used the epho function but it seems not to work properly.
<? echo woocommerce_template_single_title(); ?>
Could some one please help me with that issue, it will be verry appreciated
P.S.: I use WooCommerce and Wordpress

you should use <?php ?>
<?php echo woocommerce_template_single_title(); ?>
or
<?= woocommerce_template_single_title(); ?>

Use:
<?php
$tittle = woocommerce_template_single_title();
echo $tittle;
?>

Related

PHP shortcode input variable

I'm displaying a gallery on my wordpress site using the following code:
<?php echo do_shortcode('[satellite gallery=2 auto=off caption=off thumbs=on]'); ?>
Now I've added a custom post value/field called 'guitLink' where I can add the gallery number which I want to then use in the above shortcode, so something like this:
<?php echo do_shortcode('[satellite gallery=' .get_post_custom_values('guitLink'). 'auto=off caption=off thumbs=on]'); ?>
Any ideas how to achieve this?
Use:
<?php $guitLink = get_post_custom_values('guitLink');
echo do_shortcode('[satellite gallery=' .$guitLink[0]. ' auto=off caption=off thumbs=on]'); ?>
Instead of
<?php echo do_shortcode('[satellite gallery=' .get_post_custom_values('guitLink'). ' auto=off caption=off thumbs=on]'); ?>

woocommerce: removing link on get_categories and get_tags

I have Woocommerce outputting get_categories and get_tags in the example below, but need them to be text only. At present, it outputs text with a link to the category / tag. Can the link component be removed?
<?php echo $child_product['product']->get_categories(); ?>
<?php echo $child_product['product']->get_tags(); ?>
Thank you.
In case anyone else was looking for a solution to this...
<?php echo strip_tags ($child_product['product']->get_categories()); ?>

Show available stock quantity on product page

Firstly I would like to apologise if this question has been answered somewhere else but I am unable to find what I am looking for as I am new to PHP and assume I need this to solve my problem.
I have built a website and am using Mals-e shopping cart. I have everything up and running but I would like to show how many products are still in stock under the product description and if there are no items in stock. For example:
Available stock: 2
or
Sold Out
I have read that I need a text file with product name, price and quantity, a PHP file to read and rewrite the quantity available and out put the results on the product page and a mypage.php page but I really don't know where to start. I've spent days trying to sort this out.
I have Mysql database with some items in table called (items) with available quantity but don't know how to go about sorting it out. Any help would be most appreciated.
Thank you.
Without seeing the actual code you're using to display the product, it's hard to say buy all you should need is something like:
<?php
// get the product and stock level
if($product->numberInStock > 0) {
echo 'Available: ' . $product->numberInStock;
} else {
echo 'Out of stock';
}
If you're editing a phtml type template (HTML with embedded PHP), you might display it like:
<? if($product->numberInStock > 0): ?>
<p>Available: <?= $product->numberInStock; ?></p>
<? else ?>
<p>Out of stock</p>
<? endif; ?>
Had same issue, found out following.
Inside your catalog/product type template you can use this:
<?php
$_product = $this->getProduct();
$_qty = $_product->getStockItem()->getQty();
?>
<p>
<?php if($_qty > 0): ?>
Available: <?php echo $_qty; ?>
<?php else: ?>
Out of stock
<?php endif; ?>
</p>
session_start($_POST['quantity']);
if(isset($_POST['quantity']))
{
$postedquantity=$_POST['quantity'];
$productQuantity="20";
if($postedquantity<$productQuantity){
echo "In stock";
echo "<br/>";
}
$productQuantity=$productQuantity-$postedquantity;
echo $productQuantity."Remaining";
}
You can even do like this,storing quantity value in session and everytime it's posted it will check whether it is in stock or not and it will show how much quantity is remaining.

Magento - show custom attribute in cart

I was looking for a way to display the "estimated delivery" of a product by using the attribute 'delivery' I've made.
So far I've managed to put together this:
<?php $delivery= Mage::getSingleton('catalog/product')->load($this->getProduct()->getId())->getAttributeText('Delivery'); ?>
<?php if(isset($delivery)){
echo $delivery;
}
?>
I have added this piece to:
template/checkout/cart/item/default.phtml - between line 38/39 (Magento Version 1.6.2)
Here is the default.phtml from line 35-49 with the code added to the h2 tag:
<h2 class="product-name">
<?php $_item = $this->getItem()?>
<?// Delivery - Script ?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php $delivery= Mage::getSingleton('catalog/product')->load($this->getProduct()->getId())->getAttributeText('Delivery'); ?>
<?php if(isset($delivery)){
echo $delivery;
}
?>
<?php if ($this->hasProductUrl()):?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php else: ?>
<?php echo $this->htmlEscape($this->getProductName()) ?>
<?php endif; ?>
</h2>
The problem is, the first product added to cart is being skipped, it's always showing the attribute as not set, but the second, third and rest of the products added to cart, works great, showing their est. delivery date just fine.
From here, I'm unsure how to proceed?
Use of singleton will result in same object being called repeatedly so previous object data will get overwritten.
Once you changed from singleton to getModel you have an instance for each product so no over writing on same instance.
After some Google'ing I found this, which seems to work - But I still cannot see why, and what the big difference is, if anyone would like to clarify it, I would be very happy.
This is the working solution, it's so simple, yet I don't understand:
<?php
$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
echo $custom->getAttributeText('delivery');
?>
This does not skip the first product?
app/design/frontend/{YOURTEMPLATE}/default/template/checkout/cart/item/default.phtml
Past this code:
<?php $_item = $this->getItem(); ?>
<?php $_product = $_item->getProduct()->load(); ?>
<?php $_product->get{YOUR ATTRIBUT HERE}(); ?>

Adding additional information on cart page in magento

I am doing a magento customization site ,I need to add some additional information about the product to cart page, checkout page . I am new to magento please help how can i do this.
I tried this code in app\design\frontend\base\default\template\checkout\cart\item\default.phtml
$_product =$_item->getProductId();
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<div class="availability in-stock"><b>Compatible with : </b><div class="button2" style="color:#77C25A;"><?php echo $_additional['computer_manufacturers']['value']; echo " | "; echo $_additional['model_type']['value']; echo " | "; echo $_additional['model_version']['value'] ; ?> </div></div>
<?php endif;?>
Hi you can try the following:
$product = Mage::getModel("Catalog/Product")->load($_item->getProduct()->getId());
//echo sprintf("<pre>%s</pre>",print_r($product->getData(),true));
echo $product->getColor(); //shows the key 3
echo $product->getData('color'); //shows the key 3
echo $product->getAttributeText('color'); //shows the text blue
Make the attributes available in frontend:
On manage attribute page:
Allow HTML Tags on Frontend
Visible on Product View Page on Front-end
Remove the comment on the sprintf to see thats in there. When you have a _ in the key you should use CamelCase notation so the_color will become getTheColor().
Hope it helps !

Categories