Trouble with editing contents/message of Empty Side Cart - php

I am trying to change the default text thats in the empty side cart on WooCommerce. It just doesn't look inviting at all.
For some reason all my atempts fail, I have limited understanding of PHP but for the love of god I can't see anything wrong with me code.
This code has been added as a PHP snippet:
add_action( 'woocommerce_mini_cart_empty_message', 'custom_empty_cart_message', 10 );
function custom_empty_cart_message() {
?>
<div class="woocommerce-mini-cart__empty-message">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/SD-logo.png" alt="Empty Cart Image">
<p>Your cart is currently empty.</p>
Shop Now
</div>
<?php
}
Possible solutions that won't work include translation and gettext and replace text since I want an image and button in there. If anyone has a clue how to solve this please do reply as your help is much appreciated
Replace the default empty side cart message with an image, text and button

Related

WordPress Ajax Load More Not Displaying

I have been struggling with this problem for the last two weeks now, and the problem is that I am not able to display the ajax load more (and any of its post and even the button) on my custom archive page. I want to provide a sleek archive for my visitors, allowing them to just scroll in previous posts without having to use any pagination. And the strange thing is, when I echo the shortcode for the ajax load more, it doesn't display at all. When I inspect the code, it has been automatically set to visibility:hidden. What really seems to be the problem here?
How can I display this in my "page-arkiv.php"?
Plugin used: https://wordpress.org/plugins/ajax-load-more/
Code:
<h1>TEST PAGE </h1>
<?php echo do_shortcode('[ajax_load_more]'); ?>
Output:
<div id="ajax-load-more" class="ajax-load-more-wrap default" data-alm-id="" data-canonical-url="http://whatever.com/arkiv/" data-slug="arkiv" data-post-id="73">
<div class="alm-listing alm-ajax" data-repeater="default" data-post-type="post" data-order="DESC" data-orderby="date" data-offset="0" data-posts-per-page="5" data-scroll="true" data-scroll-distance="100" data-max-pages="0" data-pause-override="false" data-pause="false" data-button-label="Older Posts" data-transition="fade" data-images-loaded="false">
</div>
<div class="alm-btn-wrap" style="visibility: hidden;"><button class="alm-load-more-btn more " rel="next">Older Posts</button></div></div>
And this is my Reading settings:

WooCommerce: Mini cart in header seems to be cached

I've been tearing my hair out over this for two days, and every time I think I've solved it, it just pops up again.
In my header.php I have the following code for displaying the number of items in the cart, and a simple show/hide div displaying the items themselves, along with a total:
<a id="miniart" href="<?php echo WC()->cart->get_cart_url(); ?>" class="cart icon red relative">
<div class="number bold">
<?php echo sprintf('%d', WC()->cart->cart_contents_count); ?>
</div>
<div>
<?php returnIcon('cart'); // This function simply displays an inline SVG ?>
</div>
<div id="cartcontents">
<div class="widget_shopping_cart_content">
<?php woocommerce_mini_cart(); ?>
</div>
</div>
</a>
I also have a filter to return the cart fragments via AJAX when a new item is added:
function woocommerce_header_add_to_cart_fragment($fragments) {
ob_start();
?>
<div class="number bold">
<?php echo sprintf('%d', WC()->cart->cart_contents_count); ?>
</div>
<?php
$fragments['#minicart .number'] = ob_get_clean();
return $fragments;
}
add_filter('woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
The filter always works - I've never had a problem with that. What's totally throwing me is that the standard, pre-processed calls in the header (cart_contents_count & woocommerce_mini_cart()) seem to be totally cached. If I add a new item, the AJAX will update both to display 1 and the actual item added; but if I change the page or refresh, it defaults back to 0 and No items. If I go to my cart, despite the mini-cart still saying I have nothing, the actual cart page displays the cart contents correctly.
It only appears to update if I go to my cart page and delete something from my cart; for example, if I've actually got 7 items in my cart but the minicart displays 0, and then delete an item from my cart, suddenly the minicart will corectly display 6. However, from that point it will stay at 6, even if I add another dozen items.
Here's what I've tried:
Change the classes/IDs of the elements (i,e, #minicart to #tinycart, etc.) - works once, then immediately starts caching again.
Turned off the filters: This has no effect, since the filter is only for returning fragments when new items are added. Also worth noting that there doesn't appear to be any kind of AJAX call fired at page load that would interfere with the minicart display.
Turned off all plugins except WooCommerce: made no difference.
Turned off 'Enable AJAX add to cart buttons on archives' in WC settings: This kinda works, insofar as it reloads the entire page when an item is added, and the minicart displays number of cart items correctly (hooray!), but obviously disables the ability to add items via AJAX, which is a requirement of the site (boo.)
Deleting my own mini-cart.php template file: Just in case, to see if that was an issue. Made no difference.
Putting the woocommerce_mini_cart() function literally anywhere else: This, infuriatingly, works. If I take this function and the echo sprintf('%d', WC()->cart->cart_contents_count) line and put them anywhere - within the header, within the page body, even inside the same element that's getting 'cached', they work. They display the correct number of items, and the correct list of items. But the other calls to this function, as noted above, still appear to be cached.
As noted, this occurs even with no other plugins running; it happens both locally (a completely standard XAMPP installation on Windows) and remotely (a niftier nginx setup, slightly newer PHP version), and neither have any kind of caching enabled.
Any suggestions would be very gratefully received, as I have totally lost my mind on this one.
A bit late but I tried your code and it worked for me with some small modifications.
I have changed the a id from miniart to minicart and commented out the returnIcon
<a id="minicart" href="<?php echo WC()->cart->get_cart_url(); ?>" class="cart icon red relative">
<div class="number bold">
<?php echo sprintf('%d', WC()->cart->cart_contents_count); ?>
</div>
<div>
<?php //returnIcon('cart'); // This function simply displays an inline SVG ?>
</div>
<div id="cartcontents">
<div class="widget_shopping_cart_content">
<?php woocommerce_mini_cart(); ?>
</div>
</div>
</a>
Another change was to rename woocommerce_header_add_to_cart_fragment to wif_woocommerce_header_add_to_cart_fragment
function wif_woocommerce_header_add_to_cart_fragment($fragments) {
ob_start();
?>
<div class="number bold">
<?php echo sprintf('%d', WC()->cart->cart_contents_count); ?>
</div>
<?php
$fragments['#minicart .number'] = ob_get_clean();
return $fragments;
}
add_filter('woocommerce_add_to_cart_fragments', 'wif_woocommerce_header_add_to_cart_fragment');

WordPress is_page conditional causes blank page

I'm trying to use the is_page conditional tag to create a slider that displays different sets of images depending on the page.
Below I've created an example of the code I'm using. All I'm getting back is a blank page and I'm really not sure why. Everything I've looked at on Google tells me my Syntax is correct (At least from what I can tell).
I am using the is_page tag before the loop in WordPress so that shouldn't effect it as far as I'm aware. Please correct me if I'm wrong.
I tried placing <?php wp_reset_query(); ?> just before the loop too, but it had no effect.
Any ideas what I might be doing wrong?
EXAMPLE:
<div id="container">
<?php if (is_page('123') || is_page('356')){ ?> // check page, if any are true display image
<img alt="" src="<?php bloginfo('template_url');?>/images/image1.jpg" width="650" />
<?php } ?>
<?php if (is_page('123') || is_page('356') || is_page('638') || is_page('1199')){ ?> // check page, if any are true display image
<img alt="" src="<?php bloginfo('template_url');?>/images/image2.jpg" width="650" />
<?php } ?>
</div>
PROBLEM SOLVED:
<?php
// THIS GIVES US SOME OPTIONS FOR STYLING THE ADMIN AREA
function custom_design() {
echo '<style type="text/css">
#wphead{background:#592222}
#footer{background:#592222}
#footer-upgrade{background:#592222}
textarea {white-space:nowrap;overflow:scroll;}
</style>';
}
add_action('admin_head', 'custom_design');
?>
It seems this piece of code in my functions.php was causing the error. The CSS "whitespace:nowrap" was breaking any new template pages I was making. Totally bizarre. Never seen CSS do that before, at least not to that extent.
Sorry for wasting your time guys, thank you for the help. At least I know I wasn't going crazy now.
:)

my google snippet is not showing the data from the correct url

This may be a little confusing, so I added an example,
http://searchengineland.com/bing-rises-above-17-search-market-share-as-google-slips-comscore-159746
When clicking the +1 button here, inside the snippet it shows the text and URL from that page.
However, my snippet shows text from the homepage URL, not from the URL I gave it. Why is this and how can I fix it? Sorry if I'm unclear. the code I'm using is below.
<g:plusone size="medium" count="true" href="http://aaaaaa.com/social/comments/'.$row["id"].'">
</g:plusone>
The snippet is generated using the Schema.org markup on your page. To update the text, simply update the itemprop="description" value in your markup for each page within your site. This markup generally looks like:
<body itemscope itemtype="http://schema.org/Product">
<h1 itemprop="name">Shiny Trinket</h1>
<img itemprop="image" src="{image-url}" />
<p itemprop="description">Shiny trinkets are shiny.</p>
</body>
For more information on the snippet, as well as alternatives to Schema markup, see https://developers.google.com/+/web/snippet/.

How to grab variable from database and write an if statement

So, I'm using OpenCart 1.4.9.
What I want to do is grab a variable made by a custom shipping product.
The table in which it's coming from is product and the column is shipping_by_product:
I want to add a little picture when browsing through the categories so they can see it's free shipping.
Now, I was able to add this in the product detail (product.tpl template):
Using this code:
<?php if($product_info['shipping_by_product'] == '0.0000'){ ?>
<img src="LINK HERE" alt="Recommended by MADNESS">
<br />
<?php
}
?>
But that code doesn't work in category.tpl (The category template)
I get an undefined index error for $product_info and for shipping_by_product.
So I was thinking of just running a query to grab the information from the database and then add the conditional, or what other way can I do it?
Data is passed to the template by the controller, which gets it from the model (data layer). You might have to customize the controller and model to get that data if it isn't already passed. You can use the vqmod extension to add your own code in without changing the core code. Look here for info on the extension.
Figured it out.
Added: 'shipping_by_product' => $result['shipping_by_product'], to category.php
As I learned $result is pretty much the same as $product_info in this file.
Then I used this for my code:
<?php if($products[$j]['shipping_by_product'] == '0.0000'){ ?> <img style="position: absolute;margin-left: -100px;" src="IMAGE " alt="Free Continental US shipping!"> <br /> <?php } ?>
:)

Categories