Hide/Replace Buy Button on product_info
Posted: Sun Oct 24, 2021 11:46 am
On 1.0.8.6
In tpl_pi_buy_button.php I had code that worked to only show buy button when stock>0 else show a different button like:
On latest 1.0.8.7 this gives notices - it does not like $product_info.
I tried replacing the code with:
This does not give notices but shows no button at all even if stock>0
How should this be done in 1.0.8.7?
In tpl_pi_buy_button.php I had code that worked to only show buy button when stock>0 else show a different button like:
Code: Select all
<?php
if ($product_info['products_quantity'] > 0) {
echo tep_draw_button(PI_BUY_BUTTON_TEXT, 'fas fa-shopping-basket', null, 'primary', array('params' => 'data-has-attributes="' . (($products_attributes['total'] > 0) ? '1' : '0') . '" data-in-stock="' . (int)$product_info['products_quantity'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-success btn-block btn-lg btn-product-info btn-buy');
echo tep_draw_hidden_field('products_id', (int)$product_info['products_id']);
} else {
echo tep_draw_button(PI_BUY_BUTTON_UNAVAILABLE, 'fas fa-ban', null, 'primary', array('params' => 'disabled="disabled"'), 'btn-danger btn-block btn-lg');
}
?>
</div>
<?phpI tried replacing the code with:
Code: Select all
<?php
if ((int)$GLOBALS['product']->get('in_stock') > 0) {
new Button(PI_BUY_BUTTON_TEXT, 'fas fa-shopping-cart', 'btn-success btn-block btn-lg btn-product-info btn-buy', [
'data-has-attributes' => (int)$GLOBALS['product']->get('has_attributes'),
'data-in-stock' => (int)$GLOBALS['product']->get('in_stock'),
'data-product-id' => (int)$GLOBALS['product']->get('id'),
]);
new Input('products_id', ['value' => (int)$GLOBALS['product']->get('id')], 'hidden');
} else {
new Button(PI_BUY_BUTTON_UNAVAILABLE, 'fas fa-ban', 'btn-danger btn-block btn-lg', [
'disabled="disabled"'
]);
}
?>How should this be done in 1.0.8.7?