Wordpress Coding Issue - php

Being a complete numpty at this....
I am having troubles getting the below code to work (just shows the white screen of death)
case 'venue' :
if( self::isValid($atts['venue'])) {
$output .= '<td>' . apply_filters( 'ecs_event_list_venue', tribe_get_venue(), $atts ) . '</span></td>';
if( !empty(tribe_get_event_website_link()) ) {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_website_link() . '">Bookings</a></td>';
} else {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_link() . '">Read More</a></td>';
}
}
}
break;
The original code was
case 'venue' :
if( self::isValid($atts['venue'])) {
$output .= '<td>' . apply_filters( 'ecs_event_list_venue', tribe_get_venue(), $atts ) . '</span></td>';
}
break;
This works fine..
Any assistance appreciated and respected!!

You can try this :
if( self::isValid($atts['venue'])) {
$output .= '<td>' . apply_filters( 'ecs_event_list_venue', tribe_get_venue(), $atts ) . '</span></td>';
$is_value = tribe_get_event_website_link();
if( !empty($is_value) ) {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_website_link() . '">Bookings</a></td>';
} else {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_link() . '">Read More</a></td>';
}
}
You can't use function return value like this.

Related

PHP function to make more values = 0 if an id = 52 (value)

Hello i have a table when i want to display some td value = 0 if the status of the task has the id=52!
Down i will put a picture of the table!
I tried to use this code for that:
if ($status['id']) { $calC = $calCminusrealcost = $realCost =0; }
Here $calC, $calCminusrealcost and $realCost are the values i want to become 0!
Here is the pucture of the table: [!https://i.stack.imgur.com/YWOwb.png][1]][1]
So after i use this code it works but in general for all tasks, not just for those which have the id = 52, and if i try to replace id with 52 in the function it doesn't work!
Does someone know what can I do?
this is the full code i have about status:
$outputStatus = '';
$outputStatus .= '<span class="inline-block label" style="color:' . $status['color'] . ';border:1px solid ' . $status['color'] . '" task-status-table="' . $aRow['status'] . '">';
$outputStatus .= $status['name'];
if ($canChangeStatus) {
$outputStatus .= '<div class="dropdown inline-block mleft5 table-export-exclude">';
$outputStatus .= '<a href="#" style="font-size:14px;vertical-align:middle;" class="dropdown-toggle text-dark" id="tableTaskStatus-' . $aRow['id'] . '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';
$outputStatus .= '<span data-toggle="tooltip" title="' . _l('ticket_single_change_status') . '"><i class="fa fa-caret-down" aria-hidden="true"></i></span>';
$outputStatus .= '</a>';
$outputStatus .= '<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="tableTaskStatus-' . $aRow['id'] . '">';
foreach ($task_statuses as $taskChangeStatus) {
if ($aRow['status'] != $taskChangeStatus['id']) {
$outputStatus .= '<li>
<a href="#" onclick="task_mark_as(' . $taskChangeStatus['id'] . ',' . $aRow['id'] . '); return false;">
' . _l('task_mark_as', $taskChangeStatus['name']) . '
</a>
</li>';
}
}
if ($status['id']) {
$calC = $calCminusrealcost = $realCost =0;
}
$outputStatus .= '</ul>';
$outputStatus .= '</div>';
}
$outputStatus .= '</span>';
$row[] = $outputStatus;
[1]: https://i.stack.imgur.com/YWOwb.png

woocommerce_quantity_input appears twice

I have a problem with
woocommerce_quantity. Everything works fine now, but woocommerce_quantity appears twice in the frontend. I have already searched various sites and have not yet found a solution to the problem.
Here is my code:
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$current_lang = pll_current_language();
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false ); <-- Here is the quantity i needed.
$html .= '<input type="hidden" name="lightbox_for_products" value="1">';
$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</form>';
$html .= '<div id="ts_shop_modal_products" class="modal">';
$html .= '<div class="modal-content">';
$html .= '<span class="close">×</span>';
if ( $current_lang == 'de' ) {
$html .= '<button class="button alt"><a style="color: #fff" href="' . wc_get_cart_url() . '">'. pll__( 'Zum Warenkorb' ) .'</a></button><br/><br/>';
$html .= '<button class="button alt"><a style="color: #fff" href="'. get_bloginfo('url') .'/eintrittskartenshop/" >' . pll__( 'Zurück zur Übersicht' ) . '</a></button>';
} else {
$html .= '<button class="button alt"><a style="color: #fff" href="' . wc_get_cart_url() . '">'. pll__( 'Zum Warenkorb' ) .'</a></button><br/><br/>';
$html .= '<button class="button alt"><a style="color: #fff" href="'. get_bloginfo('url') .'/en/shop" >' . pll__( 'Zurück zur Übersicht' ) . '</a></button>';
}
$html .= '</div>';
$html .= '</div>';
}
In frontend it looks like this:

If statment to echo an image if var=EUR doesnt work

This code added currency switcher to a menu,
But unfortunately I don't have access to MySQL database so I can't add image "flag" to each currency, then execute them
So I tried to use if statement.
This is my code:
$currency_switcher_enable = houzez_option('currency_switcher_enable');
$is_multi_currency = houzez_option('multi_currency');
if( $currency_switcher_enable != 0 && $is_multi_currency != 1 ) {
if (class_exists('FCC_Rates')) {
$supported_currencies = houzez_get_list_of_supported_currencies();
if (0 < count($supported_currencies)) {
$current_currency = houzez_get_wpc_current_currency();
echo '<li class="btn-price-lang btn-price">';
echo '<form id="houzez-currency-switcher-form" method="post" action="#" class="open">';
echo '<button id="houzez-selected-currency" class="btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>' . $current_currency . '</span> <i class="fa fa-sort"></i></button>';
echo '<ul id="houzez-currency-switcher-list" class="dropdown-menu" aria-labelledby="dropdown" style="display:none;">';
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
if (data-currency-code='EUR') {
echo '<img src="images/euro-flag.png"';
if (data-currency-code='TR') {
echo '<img src="images/turkish-flag.png"';
}
}
echo '</ul>';
echo '<input type="hidden" id="houzez-switch-to-currency" name="houzez_switch_to_currency" value="' . $current_currency . '" />';
echo '<input type="hidden" id="currency_switch_security" name="nonce" value="' . wp_create_nonce('houzez_currency_converter_nonce') . '"/>';
echo '</form>';
echo '</li>';
}
}
}
?>
But it doesn't work? What I'm doing wrong?
This is the original code:
$currency_switcher_enable = houzez_option('currency_switcher_enable');
$is_multi_currency = houzez_option('multi_currency');
if( $currency_switcher_enable != 0 && $is_multi_currency != 1 ) {
if (class_exists('FCC_Rates')) {
$supported_currencies = houzez_get_list_of_supported_currencies();
if (0 < count($supported_currencies)) {
$current_currency = houzez_get_wpc_current_currency();
echo '<li class="btn-price-lang btn-price">';
echo '<form id="houzez-currency-switcher-form" method="post" action="#" class="open">';
echo '<button id="houzez-selected-currency" class="btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>' . $current_currency . '</span> <i class="fa fa-sort"></i></button>';
echo '<ul id="houzez-currency-switcher-list" class="dropdown-menu" aria-labelledby="dropdown" style="display:none;">';
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
}
echo '</ul>';
echo '<input type="hidden" id="houzez-switch-to-currency" name="houzez_switch_to_currency" value="' . $current_currency . '" />';
echo '<input type="hidden" id="currency_switch_security" name="nonce" value="' . wp_create_nonce('houzez_currency_converter_nonce') . '"/>';
echo '</form>';
echo '</li>';
}
}
}
?>
You have many fails here:
The first is as #kerbh0lz mentioned, the "=" and "==" is not the same purpose. here yours is wrong.
Second your second currency If is in the 1st Currency If so it wont ever pass by.
Third you are comparing a string without quote or a var without $ before data-currency-code so instead you should use $currency_code
Try this:
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
if ($currency_code =='EUR')
echo '<img src="images/euro-flag.png"';
elseif ($currency_code == 'TR')
echo '<img src="images/turkish-flag.png"';
}

on click function not working if html written inside php

see my code here
if(isset($_POST['table_category_view'])){
$result = $wpdb->get_results('SELECT id,category FROM '.$ps_category_table_name,ARRAY_A);
$html = "";
foreach ($result as $value){
$id = $value['id'];
$categry = $value['category'];
$html .= '<tr id="catgry-row' . $id . '">';
$html .= '<td id="catgry-row' . $id . '">'.$categry.'</td>';
$html .= '<td><button class="btn btn-primary btn-sm" id="edit-catgry' . $id . '" onclick="edit_category("' . $id . '");">Edit</button>';
$html .= '<button class="btn btn-danger btn-sm" id="delete-catgry' . $id . '" onclick="delete_category("' . $id . '");">Delete</button>';
$html .= '<button class="btn btn-primary btn-sm" style="display:none" id="update-catgry' . $id . '" onclick="update_category("' . $id . '");">Update</button>';
$html .= '<button class="btn btn-warning btn-sm" style="display:none" id="cancel-update-catgry' . $id . '" onclick="cancel_update_category("' . $id . '");">Cancel</button></td></tr>';
}
echo $html;
}
here how to write onclick function in my code it was not working please give me solution
enclose your sentence inside the double quote ("") not single code & write your code as below,
$html = "<td><button class='btn btn-primary btn-sm' id='edit-catgry".$id." ' onclick=edit_category('$id');>Edit</button>";
you have to write the function parameter like this in php.
onclick="edit_category('.$id.');"
Please try below code:
<?php
if(isset($_POST['table_category_view'])){
$result = $wpdb->get_results('SELECT id,category FROM '.$ps_category_table_name,ARRAY_A);
$html = "";
foreach ($result as $value){
$id = $value['id'];
$categry = $value['category'];
$html .= '<tr id="catgry-row' . $id . '">';
$html .= '<td id="catgry-row' . $id . '">'.$categry.'</td>';
$html .= '<td><button class="btn btn-primary btn-sm" id="edit-catgry' . $id . '" onclick="edit_category(' . $id . ');">Edit</button>';
$html .= '<button class="btn btn-danger btn-sm" id="delete-catgry' . $id . '" onclick="delete_category(' . $id . ');">Delete</button>';
$html .= '<button class="btn btn-primary btn-sm" style="display:none" id="update-catgry' . $id . '" onclick="update_category(' . $id . ');">Update</button>';
$html .= '<button class="btn btn-warning btn-sm" style="display:none" id="cancel-update-catgry' . $id . '" onclick="cancel_update_category(' . $id . ');">Cancel</button></td></tr>';
}
echo $html;
}
?>

Redirect from the product catalog page to the product details page instead of adding the product to the cart

I want to redirect from the product catalog page to the product details page instead of adding the product to the cart.
here is the snippet of the code.
public static function getListing($_product, $productObj, $isgrid, $isa = false)
{
$_typeId = self::getAttributeCodeForId($_product->getId(), 'type_id');
$_isReservation = self::getAttributeCodeForId($_product->getId(), 'is_reservation');
if (!self::useListButtons() || !(ITwebexperts_Payperrentals_Helper_Data::isReservationType($_product))) {
$buttonsArr = array();
if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($_product)) {
if ($_isReservation == ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL && $_typeId != ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_GROUPED) {
$addToCartTitle = Mage::helper('payperrentals')->__('Add to Queue');
} elseif ($_isReservation == ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL && $_typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_GROUPED) {
$addToCartTitle = Mage::helper('payperrentals')->__('Add All To Queue');
//check if at least one is simple and add the button addtocart
$childrensArr = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
$p = 0;
$c = 0;
foreach ($childrensArr as $iChild) {
if ($iChild->getTypeId() == 'simple') { // or configurable and isReservation=disabled or bundle and isreservation=disabled
if ($c == 0) {
$buttonsArr[] = '<p><button type="button" title="' . Mage::helper('payperrentals')->__('Add to Cart') . '" class="button btn-cart" onclick="setLocation(\'' . Mage::helper('payperrentals')->getAddToCartUrl($iChild) . '\')"><span><span>' . Mage::helper('payperrentals')->__('Add to Cart') . '</span></span></button></p>';
}
$c++;
} elseif ($iChild->getIsReservation() == ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL) {
$p++;
}
}
if ($p == 1) {
$addToCartTitle = Mage::helper('payperrentals')->__('Add to Queue');
}
if ($c > 1) {
$buttonsArr = array();
}
} else {
$addToCartTitle = Mage::helper('payperrentals')->__('Rent Now');
}
} else {
$addToCartTitle = Mage::helper('payperrentals')->__('Add To Cart');
}
$retBut = '';
if ($_isReservation == ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTALANDRESERVATION) {
$retBut .= ($isgrid ? '<div class="actions-btn">' : '<p class="actions-btn">') . '<button type="button" title="' . Mage::helper('payperrentals')->__('Add to Queue') . '" class="button btn-cart1" onclick="setLocation(\'' . Mage::helper('checkout/cart')->getAddUrl($_product, array('_query' => array('options' => array('one_option' => 'no_value'), 'is_reservation' => ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL))) . '\')"><span><span>' . Mage::helper('payperrentals')->__('Add to Queue') . '</span></span></button>
<button id="product-id-' . $_product->getId() . '" type="button" title="' . $addToCartTitle . '" class="button btn-cart" onclick="setLocation(\'' . $productObj->getAddToCartUrl($_product) . '\')"><span><span>' . Mage::helper('payperrentals')->__('Rent') . '</span></span></button>' . ($isgrid ? '</div>' : '</p>');
} elseif ($_isReservation == ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL) {
$retBut .= ($isgrid ? '<div class="actions-btn">' : '<p class="actions-btn">') . '<button type="button" title="' . $addToCartTitle . '" class="button btn-cart1" onclick="setLocation(\'' . Mage::helper('checkout/cart')->getAddUrl($_product, array('_query' => array('options' => array('one_option' => 'no_value'), 'is_reservation' => ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL))) . '\')"><span><span>' . $addToCartTitle . '</span></span></button>' . ($isgrid ? '</div>' : '</p>');
} else {
if (!$isa) {
$retBut .= ($isgrid ? '<div class="actions-btn">' : '<p class="actions-btn">') . '<button id="product-id-' . $_product->getId() . '" type="button" title="' . $addToCartTitle . '" class="button btn-cart" onclick="setLocation(\'' . $productObj->getAddToCartUrl($_product) . '\')"><span><span>' . $addToCartTitle . '</span></span></button>' . ($isgrid ? '</div>' : '</p>');
} else {
$retBut .= '<a id="product-id-' . $_product->getId() . '" title="' . $addToCartTitle . '" class="btn-cart" href="' . $productObj->getAddToCartUrl($_product) . '">' . $addToCartTitle . '</a>';
}
}
foreach ($buttonsArr as $but) {
if (!$isa) {
$retBut .= ($isgrid ? '</div>' : '') . $but . ($isgrid ? '</div>' : '');
}
}
$price = $productObj->getPriceHtml($_product, true);
if ($isgrid) {
if (count($buttonsArr) == 0) {
$action = '<div class="actions">';
} else {
$action = '<div class="actions1"><style> .products-grid .actions1 { position:absolute; bottom:3px; } .products-grid .actions1 button{ margin-top:2px; } </style>';
}
} else {
$action = '';
}
return array(
'buttons' => $retBut,
'pricing' => $price,
'action' => $action
);
} else {
if ($isgrid) {
$action = '<div class="actions">';
} else {
$action = '';
}
$price = $productObj->getPriceHtml($_product, true);
return array(
'buttons' => '',
'pricing' => $price,
'action' => $action
);
//get the defined periods for the product
//check if product is available for that period? using the startDateinitial
//modify view.phtml to use the rent buttons
}
}
So can anyone tell me where the changes and what changes have to be done to redirect to product details page

Categories