I'm using pods admin plugin and I want to change the value in array. raspored.meta_value are days from 0-6 or from Sunday to Monday.
I want that the value in raspored.meta_value = "dynamic" is changing how the days are going.
Btw: I'm new and not so good in English.Hope you understand :)
$params = array( 'limit' => -1, 'where' => 'raspored.meta_value = "4"' );
$pods = pods( 'raspored', $params );
if ( $pods->total() > 0 ) {
while( $pods->fetch() ) {
//reset id
$pods->id = $pods->id();
//get the template
$temp = $pods->template( 'Probni' );
//output template if it exists
if ( isset( $temp ) ) {
echo $pods->display( 'some_other_field' );
echo $temp;
}
}
//pagination
echo $pods->pagination();
}
else {
echo 'No content found.';
}
I found the solution.
I added if statement and change the array value for "where clause".
Example:
$params = array( 'limit' => -1, 'where' => 'raspored.meta_value = "1"', 'orderby' => 'vrijeme_start ASC' );
if (date("l") === "Monday") {
$params["where"] = array ('1');
}
elseif (date("l") === "Tuesday") {
$params["where"] = array ('2');
}
elseif (date("l") === "Wednesday") {
$params["where"] = array ('3');
}
elseif (date("l") === "Thursday") {
$params["where"] = array ('4');
}
elseif (date("l") === "Friday") {
$params["where"] = array ('5');
}
elseif (date("l") === "Saturday") {
$params["where"] = array ('6');
}
elseif (date("l") === "Sunday") {
$params["where"] = array ('0');
}
else {
echo 'Nema sadržaja';
}
Hope somebody will need this :)
Related
Fairly new to PHP and WordPress and have a query around the get_post_meta function.
So obviously the function returns the value associated with a key of a particular meta attribute but for some reason I am getting the keys returned.
The meta attribute is a selection box with a few key value pairs shown below:
function frontend_add_donation_field( $fields ) {
$fields['job']['job_donation'] = array(
'label' => __( 'Please specify the required donation amount to be paid by the successful applicant upon completion.', 'job_manager' ),
'type' => 'select',
'options' => array('tier1' => 100, 'tier2' => 200, 'tier3' => 300, 'tier4' => 400, 'tier5' => 500, 'tier6' => 600),
'required' => true,
'placeholder' => 'Please Select',
'priority' => 5
);
return $fields;
}
Now the code in the front end at the moment looks like this:
<h4><?php echo get_post_meta( $post->ID, '_job_donation', true ); ?></h4>
What I'm getting returned from this is 'tier1' etc. and not the value associated with it. (I excuse any bad coding at this stage such as escaping html ect. Just trying to get a value at the moment).
Performing a var_dump(get_post_meta( $post->ID, '_job_donation', true )) returns string(5) "tier5"
Also as per the comments, the values that are being inserted in to the array are:
array('tier1' => 100, 'tier2' => 200, 'tier3' => 300, 'tier4' => 400, 'tier5' => 500, 'tier6' => 600)
Update
The following horrible HTML gets the desired effect but really is not suitable.
<?php $donation_tier = get_post_meta( $post->ID, '_job_donation', true );
$donation = "";
if ($donation_tier === 'tier1') {
$donation = "100";
}
else if ($donation_tier === 'tier2') {
$donation = "200";
}
else if ($donation_tier === 'tier3') {
$donation = "300";
}
else if ($donation_tier === 'tier4') {
$donation = "400";
}
else if ($donation_tier === 'tier5') {
$donation = "500";
}
else if ($donation_tier === 'tier6') {
$donation = "600";
} else {
$donation = $donation_tier;
}
?>
<?php do_action( 'single_job_listing_meta_end' ); ?>
<li class="meta-important">The successful applicant will need to pay a donation of £<?php echo $donation; ?> plus an £50 standard fee to Horses 4 Homes upon completion.</li>
I think what I need to show is the key of the array element, but not sure if you can get this using the get_post_meta() function.
Is this due to the fact I'm using selection Boxes?? All of my text fields seem to be rendering correctly. Any help would be great.
Because the meta value is stored on the array form, the code should be
<?php
$donation_tier = get_post_meta( $post->ID, '_job_donation', false );
$donation = "";
if($donation_tier != null){
foreach($donation_tier as $key => $donation_tier){
if ($donation_tier === 'tier1') {
$donation = "100";
}
else if ($donation_tier === 'tier2') {
$donation = "200";
}
else if ($donation_tier === 'tier3') {
$donation = "300";
}
else if ($donation_tier === 'tier4') {
$donation = "400";
}
else if ($donation_tier === 'tier5') {
$donation = "500";
}
else if ($donation_tier === 'tier6') {
$donation = "600";
} else {
$donation = $donation_tier;
}
}
}
?>
<?php do_action( 'single_job_listing_meta_end' ); ?>
<li class="meta-important">The successful applicant will need to pay a donation of £<?php echo $donation; ?> plus an £50 standard fee to Horses 4 Homes upon completion.</li>
I'm trying to get the shipping available methods by country code that giving in the request, in the above code I'm facing an issue/conflict
That the available locations can be both a country or a continent so I need to check if this country code is a part of some continent.
the problem is with the first zone I get all methods in all zones not just within the first ( the callback return ).
The second zone which has the continents/countries ( rest of the world ) I get no issues with it but as far I guess that's because its the end of the loop. ( as I have two zones for now )
add_action("rest_api_init", function () {
register_rest_route(
"test-api/v1",
"shipping-cost",
array(
'callback' => function ($req) {
$country_code = $req->get_param('country_code');
$quantity = $req->get_param('quantity');
$shipping_cost = 0;
$methodes = [];
if (class_exists('WC_Shipping_Zones')) {
$all_zones = WC_Shipping_Zones::get_zones();
if (!empty($all_zones)) {
foreach ($all_zones as $zone) {
if (!empty($zone['zone_locations'])) {
foreach ($zone['zone_locations'] as $location) {
$wc_contries = new WC_Countries();
$continent_code = $wc_contries->get_continent_code_for_country($country_code);
if ($country_code === $location->code || $continent_code === $location->code) {
if (!empty($zone['shipping_methods'])) {
$shipping_method_ctrl = new WC_REST_Shipping_Zone_Methods_Controller();
foreach ($zone['shipping_methods'] as $flat_rate) {
$shipping_method = $shipping_method_ctrl->prepare_item_for_response($flat_rate, $req);
$methodes[] = (object) $shipping_method;
}
}
}
}
}
}
}
}
return $methodes;
}
)
);
});
Here's the answer: ( adding break with the number of the array want it to be stop )
Register_rest_route(
"kefan-api/v1",
"shipping-cost",
array(
'callback' => function ($req) {
$country_code = $req->get_param('country_code');
$methodes = [];
if (class_exists('WC_Shipping_Zones')) {
$all_zones = WC_Shipping_Zones::get_zones();
if (!empty($all_zones)) {
foreach ($all_zones as $zone) {
if (!empty($zone['zone_locations'])) {
foreach ($zone['zone_locations'] as $location) {
$wc_contries = new WC_Countries();
$continent_code = $wc_contries->get_continent_code_for_country($country_code);
if ($country_code === $location->code || $continent_code === $location->code) {
if (!empty($zone['shipping_methods'])) {
$shipping_method_ctrl = new WC_REST_Shipping_Zone_Methods_Controller();
foreach ($zone['shipping_methods'] as $flat_rate) {
$shipping_method = $shipping_method_ctrl->prepare_item_for_response($flat_rate, $req);
$methodes[] = (object) $shipping_method;
}
break 2;
}
}
}
}
}
}
}
return $methodes;
}
)
);
I created a new column in the "sales_flat_order" table called "gc_sent", default value of 0.
From here, I'm trying to perform an if statement below in the code, saying if the Card's gc_sent is 0, then send an email to the customer with their giftcard in it. Then set the card_status to 1, and gc_sent to 1.
However, what I'm running into in my dev environment, I'm receiving email after email, 1 per minute, with my gift card information in it. That shouldn't be happening. That's what I'm trying to prevent. That's why I'm doing conditions including curDate (current date), and MailDeliveryDate. To ensure that everything jives.
So, what am I doing wrong? What do I need to change? I'm relatively new to Magento, only been doing it for a few months now, by the way.
The most relevant section is:
$curDate = date('Y-m-d');
$cards = Mage::getModel('giftcards/giftcards')->getCollection()
->addFieldToFilter('order_id', $order->getId())
->addFieldToFilter('gc_sent', 0);
foreach($cards as $card) {
if (($card->getGcSent() == 0) && ($curDate == $card->getMailDeliveryDate())) {
if ((($card->getMailDeliveryDate() == null) || ($curDate == $card->getMailDeliveryDate())) && $card->getCardType() != 'offline') {
$this->_send($post, 'giftcards/email/email_template', $mail, $storeId);
$card->setCardStatus(1)->save();
$order->setGcSent(1)->save();
}
}
}
But this is the complete code:
<?php
class Sportys_Giftcardoverride_Model_Giftcards extends Webtex_Giftcards_Model_Giftcards
{
protected function _sendEmailCard($storeId = 0)
{
if($order = Mage::getModel('sales/order')->load($this->getOrderId())){
$storeId = $order->getStoreId();
} else {
$storeId = 1;
}
$amount = number_format(Mage::app()->getStore($storeId)->convertPrice($this->getCardAmount(), false, false),2);
if(Mage::helper('giftcards')->isUseDefaultPicture() || !$this->getProductId()) {
$picture = Mage::getDesign()->getSkinUrl('images/giftcard.png',array('_area'=>'frontend'));
} else {
$product = Mage::getModel('catalog/product')->load($this->getProductId());
if (!$product->getId() || $product->getImage() != 'no_selection') {
$picture = Mage::helper('catalog/image')->init($product, 'image');
} else {
$picture = Mage::getDesign()->getSkinUrl('images/giftcard.png',array('_area'=>'frontend'));
}
}
//Change picture if one is found in picture array
$cardDesigns = __DIR__ . '/../../../../../../sportysadmin/giftcarddesigns.php';
if(file_exists($cardDesigns)){
include $cardDesigns;
}
$post = array(
'amount' => $this->_addCurrencySymbol($amount,$this->getCardCurrency()),
'code' => $this->getCardCode(),
'email-to' => $this->getMailTo(),
'email-from' => $this->getMailFrom(),
'recipient' => $this->getMailToEmail(),
'email-message' => nl2br($this->getMailMessage()),
'store-phone' => Mage::getStoreConfig('general/store_information/phone'),
'picture' => $picture,
);
$mail = trim($this->getMailToEmail()) ;
if(empty($mail)) {
$mail = $order->getCustomerEmail() ;
}
$curDate = date('Y-m-d');
$cards = Mage::getModel('giftcards/giftcards')->getCollection()
->addFieldToFilter('order_id', $order->getId())
->addFieldToFilter('gc_sent', 0);
foreach($cards as $card) {
if (($card->getGcSent() == 0) && ($curDate == $card->getMailDeliveryDate())) {
if ((($card->getMailDeliveryDate() == null) || ($curDate == $card->getMailDeliveryDate())) && $card->getCardType() != 'offline') {
$this->_send($post, 'giftcards/email/email_template', $mail, $storeId);
$card->setCardStatus(1)->save();
$order->setGcSent(1)->save();
}
}
}
}
protected function _send($post, $template, $email, $storeId)
{
if ($email) {
$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);
$postObject = new Varien_Object();
$postObject->setData($post);
$postObject->setStoreId($storeId);
$mailTemplate = Mage::getModel('core/email_template');
$pdfGenerator = new Webtex_Giftcards_Model_Email_Pdf();
//$this->_addAttachment($mailTemplate, $pdfGenerator->getPdf($postObject), 'giftcard.pdf');
$mailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
->sendTransactional(
Mage::getStoreConfig($template, $storeId),
'general',
$email,
null,
array('data' => $postObject)
);
$translate->setTranslateInline(true);
} else {
throw new Exception('Invalid recipient email address.');
}
}
}
?>
the problem is in your below code
if ((($card->getMailDeliveryDate() == null) || ($curDate == $card->getMailDeliveryDate())) && $card->getCardType() != 'offline') {
$this->_send($post, 'giftcards/email/email_template', $mail, $storeId);
$card->setCardStatus(1)->save();
$order->setGcSent(1)->save();
}
you are setting setGcSent(1) on $order instead of $card try changing that code to
$card->setCardStatus(1)
->setGcSent(1)
->save();
I want to count the rows based on like and unlike value in an array.I want to count the rows based on like and unlike value.I need to display like:3 and unlike:1.Now it display like:0,unlike:0 '$content' value is either {"userid":"1","like":"1"} or {"userid":"1","unlike":"1"}
$like_count = 0;
$unlike_count = 0;
while($like_fet = mysql_fetch_assoc($query))
{
$content = $like_fet['CONTENT_VALUE'];
$datas = json_decode($content);
foreach($datas as $item)
{
$like = $item['like'];
$unlike = $item['unlike'];
if($like != '' && $unlike == '')
{
echo "like";
$like_count++;
}
if($unlike != '' && $like == '')
{
echo "unlike";
$unlike_count++;
}
}
}
$like_count=0;
$unlike_count=0;
while($like_fet=mysql_fetch_assoc($query)) {
$json = json_decode($like_fet['CONTENT_VALUE'], true);
if ( isset($json['like']) ) {
$like_count += $json['like'];
}
if ( isset($json['unlike']) ) {
$unlike_count += $json['unlike'];
}
}
depending on how CONTENT_VALUE actually works this can probably simplified to
$like_count=0;
$unlike_count=0;
while($like_fet=mysql_fetch_assoc($query)) {
$json = json_decode($like_fet['CONTENT_VALUE'], true);
if ( isset($json['like']) ) {
$like_count++;
}
else if ( isset($json['unlike']) ) {
$unlike_count++;
}
else {
trigger_error('CONTENT_VALUE without like/unlike element', E_USER_NOTICE);
}
}
I've a following code snippet from smarty template:
<div class="pagination">
{pagination_link_01 values=$pagination_links}
</div>
The following is the function body:
<?php
function smarty_function_pagination_link_01($params, &$smarty)
{
if ( !is_array($params['values']) )
{
return "is not array";
}
if ( 0 == count($params['values']) )
{
return "Empty Array";
}
if ( empty($params['values']['current_page']) )
{
return "Invalid Request";
}
$values = $params['values'];
//Seperator Used Betwinn Pagination Links
$seprator = empty( $params['seperator'] ) ? " " : $params['seperator'];
//Class Name For Links
$extra = empty( $params['extra'] ) ? "" : $params['extra'];
$current_page = (int)$values['current_page'];
if ( !empty($values['first']) )
{
//$ret[] = "<a $extra href='{$values['first']}' ><First</a>";
}
if ( !empty($values['previous'] ) )
{
$ret[] = "<a $extra href='{$values['previous']}' class='prev active'><span></span></a>";
}
$ret[] = "<ul>";
foreach( $values as $k => $v )
{
if( is_numeric( $k ) )
{
if ( $k == $current_page)
{
$ret[] = "<li><a $extra class='active'>$k</a></li>";
}
else
{
$ret[] = "<li><a $extra href='$v'>$k </a></li>";
}
}
}
if ( !empty($values['next'] ) )
{
$ret[] = "</ul><a $extra href='{$values['next']}' class='next active'><span></span></a>";
}
if ( !empty($values['last'] ) )
{
//$ret[] = "<a $extra href='{$values['last']}' >Last></a>";
}
//$str_ret = $first . $previous . $str_ret . $next . $last;
if ( $ret )
{
return implode( $seprator, $ret );
}
}
?>
If I print $params I'm getting the values I passed by means of an array $pagination_links. Similarly I want to add one more argument named $total_pages to the above function call and use it in the function body. I tried many ways but it couldn't happen. Can anyone please guide me in this regard please. Thanks in advance.
You call it like this, where $pages is the variable you want to pass:
<div class="pagination">
{pagination_link_01 values=$pagination_links total_pages=$pages}
</div>
and then in the function
if isset($params['total_pages'])
{
... do something with $params['total_pages']...
}
You didn't post much of your code but can't you just pass it to the function?
call your function with your variable. smarty_function_pagination_link_01($params,&$smarty, $total_pages);
e.g.
function smarty_function_pagination_link_01($params, &$smarty, $total_pages)
{