Woocommerce 'recent products' assistance - php

I am using the shortcode [recent_products per_page="3" columns="3"] in one of my pages.
I am unable to edit this page in the mytheme/woocommerce/content-widget-product.php page but any changes I am making are not getting applied. Am I editing the correct file? Is there a way to edit how this shortcode displays that I do not know about?
Any assistance to resolve this issue is appreciated.
<?php global $product; ?>
<li>
<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">
<?php echo $product->get_image(); ?>
<span class="product-title"><?php echo $product->get_title(); ?></span>
</a>
<?php if ( ! empty( $show_rating ) ) echo $product->get_rating_html(); ?>
<?php echo $product->get_price_html(); ?>
</li>
This is the code that I am trying to edit - to no avail.

Check if you update the files on server.
If you bought the template, probably you haven't access to the code of that widget.
Anyway, I think you are editing the wrong file.
Show some code please

Related

Trying do_shortcode inside template file but need php inside do_shortcode

i have a php template for a posts archive and that is the part
<h3 class="entry-title mh-posts-grid-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h3>
Now i want to use this inside a shortcode and i tried it only with the part of the_title();
I tried several solutions i found here. When i try it with simple html instead of the_title() it works, but as soon as i try it with the_title i get errors or the title doesn't appear. I need enclosing shortcodes
What i tried
<?php echo do_shortcode( '[um_loggedin] $the_title [/um_loggedin]' );?
<?php echo do_shortcode( '[um_loggedin] $the_title() [/um_loggedin]' );?
<?php echo do_shortcode( '[um_loggedin] $the_title(); [/um_loggedin]' );?
Same without $
Thanks for any help :(
Now i have found the solution myself
echo do_shortcode('[um_loggedin]'.get_the_title().' [/um_loggedin]');

Show cart and chekout in the header woocomerece

Hi all maybe someone is aware on how to add cart page and checkout page content into the header.php so it shows on every page? tried looking but haven't found a proper answer. any help is appreciated.
No need to write a single piece of code ;)
A free plugin is already available in Wordpress and it will let you add minicart as a widget to any of your sidebar (here in top bar).
Hi, the below code may help you
<?php
global $woocommerce;
$qty = $woocommerce->cart->get_cart_contents_count();
$total = $woocommerce->cart->get_cart_total();
$cart_url = $woocommerce->cart->get_cart_url();
echo $loginout = wp_loginout($_SERVER['REQUEST_URI'], false ); // show wp dynamic login / logout link
?>
<a href="<?php echo $woocommerce->cart->get_checkout_url() ?>" title="<?php _e( 'Checkout' ) ?>">
<?php _e( 'Checkout' ) ?>
</a> |
<a href="<?php echo $cart_url ?>" title="<?php _e( 'Cart' ) ?>">
<?php _e( 'Cart ( '. $qty .' ) -'. $total ) ?>
</a>

Remove word from Woocommerce count span in cart header

Does somebody know, where I can find the .php file in woocommerce, where I can remove the word "item" or "items" from the last span?
I've tried it with some jQuery Code but it only works when I load the page completely. When I click add to cart or remove from cart an item, the cart only reload in woocommerce without my .js file to remove the two words.
Can anybody help me?
Thank you
$('.count').html($('.count').html().replace(' items',''));
$('.count').html($('.count').html().replace(' item',''));
<a class="cart-contents" href="http://*****.de/warenkorb/" title="View your shopping cart">
<span class="amount">0,00 €</span>
<span class="count">0 items</span><!--Here I want to remove the Word items to show just the number-->
</a>
After a few days of breaking my head about this i've found a solution (I'm so happy and angry too because when you know the answer the solution is so easy).
First you have to find the file woocommerce/templates/cart/mini-cart.php to overwrite our function.
When you've found it you have to find following line:
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?></li>
After you've found it you have to insert following code under the line:
<?php
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
<span class="count"><?php echo sprintf (_n( '%d', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?></span>
</a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
?>
Now you have to save the file and reload the page and put something in your cart (or remove) to update your cart. Know it should be done! :-)
If you want to add your price to the header too you also have to add above <span class="count"> following lines of code:
<span class="amount"><?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?></span>
If you have any questions you can always comment me…
To avoid the risk of these adjustments being overwritten if you update Storefront, you can also rewrite the function in your functions.php file like this:
if ( ! function_exists( 'storefront_cart_link' ) ) {
function storefront_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'storefront' ); ?>">
<?php /* translators: %d: number of items in cart */ ?>
<?php echo wp_kses_post( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
</a>
<?php
}
}

Woocommerce Storefront template-tags.php changes to storefront_cart_link() not possible

I am using WordPress 4.3.1, Woocommerce 2.4.7 and the theme storefront 1.5.1.
I want to change the "site-header-cart" in the header, that displays the current price of the cart along the amount of items in the cart, to only show the number of items:
<span class="amount">463,33 €</span>
<span class="count">7 items</span>
Should be:
<span class="count">7</span>
Whenever I make changes to template-tags.php only changes outside of the
<a class="cart-contents" ...>
...
</a>
are being displayed. Whenever I try to change something inside the href the unchanged original will show up:
if ( ! function_exists( 'storefront_cart_link' ) ) {
function storefront_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
<span class="count"><?php echo wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'storefront' ), WC()->cart->get_cart_contents_count() ) );?></span>
</a>
<?php
}
}
Whats going on, can anyone help me ?
I had the same Issue. The fact is, that you have to make a operation on the cart like add a item or empty the cart to get your changes visible. Another option is clearing the sessionStorage like Loque described.
1. Add code to your custom functions.php
if ( ! function_exists( 'storefront_cart_link' ) ) {
function storefront_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
<span class="count"><?php echo WC()->cart->get_cart_contents_count();?></span>
</a>
<?php
}
}
2. Do a operation on the cart or clear the sessionStorage in Console:
sessionStorage.removeItem('wc_fragments')
3. Refresh your Browser --> very Important
Before:
<span class="count">1 items</span>
After:
<span class="count">1</span>

Getting wrong permalink for view order in woocommerce

I made a custom template for my-orders.php and to show specification of an order when I add the links, I get
view-order/?order="order number" as permalink. should me view-order/"ordernumber"
Code added:
?><tr class="order">
<td class="order-number">
<a href="<?php echo $order->get_view_order_url(); ?>">
<?php echo $order->get_order_number(); ?>
</a>
</td>
yeah I found this problem as well.
I spent some time trying to manipulate the woo commerce 2.1 before I realized it wasn't even being used.
Instead my theme actually had it's own account pages which didn't work with the 2.1 that was causing the problem. So I found a file in my theme called my-orders.php and had to yank out the part I didn't want:
The guilty code was caused by
<a href="<?php echo esc_url( add_query_arg('order', $order->id, get_permalink( woocommerce_get_page_id( 'view_order' ) ) ) ); ?>">
and I just pulled out the offending non compatible with 2.1 bits:
<a href="<?php echo str_replace('?order=','',esc_url( add_query_arg('order', $order->id, get_permalink( woocommerce_get_page_id( 'view_order' ) ) ) ) ); ?>">
I actually had to make this change in 2 place in this file
I'm just pulling about the old style url:
str_replace('?order=','', OFFENDING STRING )
You should check your permalink structure in the WordPress settings. $order->get_view_order_url(); will give you pretty perma structure if your settings are correct.

Categories