I am trying to display the products/items within a WooCommerce order using the following php, but the items are not being shown.
The code I am using is an adaptation of this: Get cart item name, quantity all details woocommerce
Using the original code from the question above also does not display anything on my page.
Thanks in advance.
<?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = $values['data']->post;
//product image
$getProductDetail = wc_get_product( $values['product_id'] );
echo '<tr><td>';
echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
echo '</td>';
echo '<td>';
echo '<p style="font-size:10pt;">'.$_product->post_title.'</p><td><p style="font-size:10pt;">x'. $values['quantity'] . '</p></td>';
echo '</td></tr>';
};
?>
The full page code is here:
<?php
/*
Template Name: Store
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
?>
<!DOCTYPE HTML>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
<?php _e('Store Queue'); ?>
</title>
</head>
<body id="driverqueue">
<header>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 class="title"><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</header>
<section>
<?php
global $woocommerce;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'wc-processing',
'meta_key' => '_customer_user',
'posts_per_page' => '-1'
);
$my_query = new WP_Query($args);
$customer_orders = $my_query->posts;
foreach ($customer_orders as $customer_order) {
$order = new WC_Order();
$order->populate($customer_order);
$orderdata = (array) $order;
// $orderdata Array will have Information. for e.g Shippin firstname, Lastname, Address ... and MUCH more.... Just enjoy!
}
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
?>
<table class="ordertable" id="<?php echo $order_id; ?>">
<tr>
<td>
<p>Order #
<?php echo $order_id; ?> —
<time datetime="<?php the_time('c'); ?>">
<?php echo the_time('d/m/Y g:i:s A'); ?>
</time>
</p>
</td>
<td>
<?php echo $order->billing_first_name . ' ' . $order->billing_last_name ?>
</td>
<td>
<table>
<tr>
<?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = $values['data']->post;
//product image
$getProductDetail = wc_get_product( $values['product_id'] );
echo '<tr><td>';
echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
echo '</td>';
echo '<td>';
echo '<p style="font-size:10pt;">'.$_product->post_title.'</p><td><p style="font-size:10pt;">x'. $values['quantity'] . '</p></td>';
echo '</td></tr>';
};
?>
</tr>
</table>
</td>
<td>
<p>
<?php
do_action( 'woocommerce_admin_order_actions_start', $order );
$actions = array();
if ( $order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
$actions['complete'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=awaiting-shipment&order_id=' . $post->ID ), 'woocommerce-mark-order-status' ),
'name' => __( 'Complete', 'woocommerce' ),
'action' => "complete"
);
};
$actions = apply_filters( 'woocommerce_admin_order_actions', $actions, $order );
foreach ( $actions as $action ) {
printf( '<a class="button %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
}
do_action( 'woocommerce_admin_order_actions_end', $order );
?>
</p>
</td>
<td>
<form action="">
<input type="checkbox" class="ordercollected" value="0" />
</form>
</td>
</tr>
<?php endwhile; ?>
</section>
</body>
</html>
Solved this using info from the following link with the adapted code below:
https://wordpress.stackexchange.com/questions/180075/how-to-get-woocommerce-order-product-info
<?php
foreach ($order->get_items() as $key => $lineItem) {
//uncomment the following to see the full data
// echo '<pre>';
// print_r($lineItem);
// echo '</pre>';
$product_id = $lineItem['product_id'];
$product = wc_get_product( $product_id );
echo '<tr><td>' . $product->get_image() . '</td>'; // accepts 2 arguments ( size, attr )
echo '<td>' . 'Product: ' . $lineItem['name'] . '</td>';
echo '<td> x' . $lineItem['qty'] . '</td></tr>';
}
?>
Related
I have writtern a function which shows my woocommerce product categories as tabs and related products as tab content.
`<?php
$product = wc_get_product( $post->ID );
if ( has_post_thumbnail( $product->id ) ) {
$attachment_ids[0] = get_post_thumbnail_id( $product->id );
$attachment = wp_get_attachment_image_src($attachment_ids[0], 'full' );
}
$categories = get_terms( array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
) );
echo '<div class="tabs-container">';
echo '<ul class="tabs">';
foreach ( $categories as $category ) {
echo '<li class="tab">' . $category->name . '</li>';
}
echo '</ul>';
foreach ( $categories as $category ) {
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $category->slug,
),
),
);
$query = new WP_Query( $args );
echo '<div id="' . $category->slug . '" class="tab-content car">';
while ( $query->have_posts() ) {
$query->the_post();
echo '<div class="post-cont">';
if ( has_post_thumbnail( $product->id ) ) {
$attachment_ids[0] = get_post_thumbnail_id( $product->id );
$attachment = wp_get_attachment_image_src($attachment_ids[0], 'full' ); ?>
<img src="<?php echo $attachment[0] ; ?>" class="card-image" />
<?php } ?> <br>
<div class="post-details">
<div class="post-title">
<?php the_title(); ?>
</div>
<div class="shop-button-cont">
<div class="shop-button"><?php echo 'Shop Now'; ?></div>
<div class="sale-prise">
<?php echo $price = get_post_meta( get_the_ID(), '_sale_price', true);?>
</div>
<div class="reg-prise">
<?php echo $sale = get_post_meta( get_the_ID(), '_regular_price', true); ?>
</div>
</div>
</div><?php
echo '</div>';
}
echo '</div>';
}
echo '</div>';
wp_reset_postdata();
?>
<script>document.addEventListener("DOMContentLoaded", function() {
var tabs = document.querySelectorAll(".tabs li");
var tabContents = document.querySelectorAll(".tab-content");
tabs.forEach(function(tab) {
tab.addEventListener("click", function() {
var tabId = this.querySelector("a").getAttribute("href");
tabContents.forEach(function(content) {
content.style.display = "none";
});
document.querySelector(tabId).style.display = "flex";
tabs.forEach(function(tab) {
tab.classList.remove("active");
});
this.classList.add("active");
});
});
});</script>
`
but when we load the page all the tabs are closed, but i want to add a tab which shows all the product and is active by default when page is load.
is there any way to achive this? and if you want to change the whole fuction with a better function than it is also welcomed
Edit:
<?php
$product = wc_get_product( $post->ID );
if ( has_post_thumbnail( $product->id ) ) {
$attachment_ids[0] = get_post_thumbnail_id( $product->id );
$attachment = wp_get_attachment_image_src($attachment_ids[0], 'full' );
}
$categories = get_terms( array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
) );
echo '<div class="tabs-container">';
echo '<ul class="tabs">';
echo '<li class="tab active">All</li>';
foreach ( $categories as $category ) {
echo '<li class="tab">' . $category->name . '</li>';
}
echo '</ul>';
echo '<div id="all" class="tab-content car">';?>
// Query and display all products here
<h1>Prodcuts</h1>
<div class="post-intro">Kuch Saste mai dikahu madam? <img src="https://images.all-free-download.com/images/graphicwebp/road_tested_208353.webp" alt=""></div>
<?php
// Set the number of posts to fetch and the offset (i.e. how many posts to skip)
$num_posts = 3;
$offset = 0;
$product = wc_get_product( $post->ID );
$price = get_post_meta( get_the_ID(), '_regular_price', true);
// $price will return regular price
$sale = get_post_meta( get_the_ID(), '_sale_price', true);
// $sale will return sale price
// Create a new instance of the WP_Query class
$posts = new WP_Query( array(
'post_type' => 'product', // Fetch only posts (not pages or other post types)
'posts_per_page' => $num_posts, // Set the number of posts to fetch
'offset' => $offset // Set the offset (how many posts to skip)
) );
// Check if the query has posts
if ( $posts->have_posts() ) {
// Loop through the posts and output their data
while ( $posts->have_posts() ) {
$posts->the_post(); ?>
<div class="post-cont">
<?php if ( has_post_thumbnail( $product->id ) ) {
$attachment_ids[0] = get_post_thumbnail_id( $product->id );
$attachment = wp_get_attachment_image_src($attachment_ids[0], 'full' ); ?>
<img src="<?php echo $attachment[0] ; ?>" class="card-image" />
<?php } ?><br>
<div class="post-details">
<div class="post-title">
<?php the_title(); ?>
</div>
<div class="shop-button-cont">
<div class="shop-button"><?php echo 'Shop Now'; ?></div>
<div class="sale-prise">
<?php echo $price = get_post_meta( get_the_ID(), '_sale_price', true);?>
</div>
<div class="reg-prise">
<?php echo $sale = get_post_meta( get_the_ID(), '_regular_price', true); ?>
</div>
</div>
</div>
</div>
<?php
}
} else {
}
// Reset the post data after the query
wp_reset_postdata();
?>
</div>
<?php echo '</div>';
foreach ( $categories as $category ) {
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $category->slug,
),
),
);
$query = new WP_Query( $args );
echo '<div id="' . $category->slug . '" class="tab-content car">';
while ( $query->have_posts() ) {
$query->the_post();
echo '<div class="post-cont">';
if ( has_post_thumbnail( $product->id ) ) {
$attachment_ids[0] = get_post_thumbnail_id( $product->id );
$attachment = wp_get_attachment_image_src($attachment_ids[0], 'full' ); ?>
<img src="<?php echo $attachment[0] ; ?>" class="card-image" />
<?php } ?> <br>
<div class="post-details">
<div class="post-title">
<?php the_title(); ?>
</div>
<div class="shop-button-cont">
<div class="shop-button"><?php echo 'Shop Now'; ?></div>
<div class="sale-prise">
<?php echo $price = get_post_meta( get_the_ID(), '_sale_price', true);?>
</div>
<div class="reg-prise">
<?php echo $sale = get_post_meta( get_the_ID(), '_regular_price', true); ?>
</div>
</div>
</div><?php
echo '</div>';
}
echo '</div>';
}
echo '</div>';
wp_reset_postdata();
?>
<script>
document.addEventListener("DOMContentLoaded", function() {
var tabs = document.querySelectorAll(".tabs li");
var tabContents = document.querySelectorAll(".tab-content");
tabs.forEach(function(tab) {
tab.addEventListener("click", function() {
var tabId = this.querySelector("a").getAttribute("href");
if (tabId === "#all") {
tabContents.forEach(function(content) {
content.style.display = "none";
});
} else {
tabContents.forEach(function(content) {
content.style.display = "none";
});
document.querySelector(tabId).style.display = "flex";
}
tabs.forEach(function(tab) {
tab.classList.remove("active");
});
this.classList.add("active");
});
});
});
</script>
You can add 'active' class in the PHP on one of the li tags.
echo '<div class="tabs-container">';
echo '<ul class="tabs">';
foreach ( $categories as $category ) {
$active_class = ( $category->slug === 'first-category' ) ? 'active' : '';
echo '<li class="tab ' . $active_class . '">' . $category->name . '</li>';
}
echo '</ul>';
Or you can use javascript to add the active class after the page is loaded.
// Get the list of tabs
var tabsList = document.querySelector('.tabs');
// Get the first tab
var firstTab = tabsList.firstElementChild;
// Add the "active" class to the first tab
firstTab.classList.add('active');
I have a rather neat filter tag that will narrow down results in a specific post category to just the posts within that category that have the selected tag.
I am struggling to get the stock 'select tag...' option to reset the filter and show all results again - so once a user selects a tag the only way to reset the list is by refresh.
Here is my filter within the function.php script:
// CASE STUDY FILTER
function my_filters(){
$args = array(
'orderby' => 'date',
'order' => $_POST['date']
);
if( isset( $_POST['tagfilter'] ) ):
$args['tax_query'] = array(
array(
'taxonomy' => 'post_tag',
'field' => 'id',
'terms' => $_POST['tagfilter']
)
);
$query = new WP_Query( $args );
if( $query->have_posts() ):
while( $query->have_posts() ):
$query->the_post();
echo "<article class=\"post-box " . get_post_class() . "\">";
echo "";
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' );
echo "<div class=\"cs-image\" style=\"background-image: url('" . $url . "')\"></div>";
$case_study = get_field('case_study_page_content');
if( $case_study ):
echo "<div class=\"cs-text-container\">";
while( have_rows('case_study_page_content') ): the_row();
$case_study_title = get_sub_field('title');
$case_study_author = get_sub_field('author');
echo "<h2>" . $case_study_title . "</h2>";
echo "<p>" . $case_study_author . "</p>";
endwhile;
echo "</div>";
endif;
echo "</article>";
endwhile;
wp_reset_postdata();
else :
echo 'No case studies found';
endif;
die();
endif;
}
add_action('wp_ajax_customfilter', 'my_filters');
add_action('wp_ajax_nopriv_customfilter', 'my_filters');
// END CASE STUDY FILTER
The form that this takes input from is here:
<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="advanced-filterform">
<?php
if( $terms = get_terms( 'post_tag', 'orderby=name' ) ) :
echo '<select class="tagfilter" name="tagfilter"><option>Select tag...</option>';
foreach ( $terms as $term ) :
echo '<option value="' . $term->term_id . '">' . $term->name . '</option>';
endforeach;
echo '</select>';
endif;
?>
<button>Apply filters</button>
<input type="hidden" name="action" value="customfilter">
</form>
As simply as possible without creating a tag on every post - how can I implement this.
i have an custom single post and show the product price and product tags and content , now i need show the product attribute in below of content but i test the many code , i can't show in my single post .
i need a code for echothe product attribute in single post .
this is my single.php
<?php get_header(); ?>
<div itemscope itemtype="http://schema.org/Product" id="single">
<div id="similar">
<h2><i class="icon-film"></i>similar product</h2>
<?php
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'post_type' => 'product' , 'orderby' => 'rand' , 'numberposts' => 8, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<?php if ( has_post_thumbnail() ) {the_post_thumbnail('first-thumb');} else { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php bloginfo('template_directory'); ?>/assets/img/no-image.png" alt="<?php the_title(); ?>" /><?php } ?></a>
<?php }
wp_reset_postdata(); ?>
<ul class="product_tags">
<h3><i class=" icon-uniE887"></i>product tag</h3>
<?php woocommerce_product_loop_tags() ?>
</ul>
</div>
<div id="single_body">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="h1"><i class="icon-quill"></i><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<h1><span itemprop="name">
<?php the_title(); ?>
</span></h1>
</a>
<ul class="title_icon">
<li title="view"><i class="icon-uniE850"></i><?php if(function_exists('the_views')) { the_views(); } ?></li>
<li title="comment"><i class="icon-bubbles2"></i><?php comments_popup_link('0 ','1 ', '% '); ?></li>
<li title="date"><i class="icon-clock"></i><?php the_time('Y/m/d') ?></li>
</ul>
</div>
<p><?php the_content()?></p>
<?php endwhile;endif; ?>
</div>
<ul class="product_etc">
<h3><i class="icon-uniE02A"></i>detail of productل</h3>
<li itemprop="offers" itemscope itemtype="http://schema.org/Offer"><strong>price</strong>
<div class="price" itemprop="price" ><?php echo $product->get_price_html(); ?></div></li>
<li><strong>category</strong><span><?php echo $product->get_categories( ', ', '' . _n( '', '', sizeof( get_the_terms( $post->ID, '' ) ), '' ) . ' ', '' ); ?></span></li>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</ul>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="comments-page"><?php comments_template(); ?></div>
<?php wp_reset_query(); ?>
<?php get_footer(); ?>
and this is my function.php
<?php
add_filter('show_admin_bar','__return_false');
function the_content_limit($max_char, $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content,'');
if (strlen($_GET['p']) > 0) {
echo "<p>";
echo $content;
echo "</p>";
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = mb_substr($content, 0, $espacio);
$content = $content;
echo "<p>";
echo $content;
echo "...";
echo "</p>";
}
else {
echo "<p>";
echo $content;
echo "</p>";
}
}
//thumbnails
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
}
//comments
if ( $_GET['post_type'] != 'page' ) {add_post_meta($post_id, 'series', '', true);}
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div id="comments_data">
<?php printf( __( '<span class="">نظر</span> <cite class="fn">%s</cite>' ), get_comment_author_link() ); ?>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __('<span class="">در تاریخ: </span><br/> %1$s'), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
?>
</div>
</div>
<?php comment_text(); ?>
<!---<div class="comment-author vcard">
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
</div>--->
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php
}
//woocommerce
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.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 WC()->cart->get_cart_url(); ?>"><?php echo sprintf (_n( '%d محصول', '%d محصول', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> به ارزش <?php echo WC()->cart->get_cart_total(); ?></a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_product_loop_tags', 5 );
function woocommerce_product_loop_tags() {
global $post, $product;
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( '', '', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
}
add_action( 'woocommerce_single_product_summary', 'product_attribute_after_price', 15 );
function product_attribute_after_price () {
global $product;
// HERE add your product attribute SLUG or taxonomy
$attribute_slug = 'color';
$taxonomy = strpos($url, 'blog') !== false ? $attribute_slug : 'pa_' . $attribute_slug;
$attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
$term_name = $product->get_attribute( $taxonomy ); // The value
if( empty($term_name) ) return; // Exit if empty value
// If not empty we display it
$output = '<div class="product-attribute '.$taxonomy.'"><p>';
$output .= '<strong> '.$attribute_name.'</strong>: ';
$output .= '<span> '.$term_name.'</span>';
echo $output . '</p></div>';
}
?>
To display product attributes, you will use this in any hooked function or Woocommerce templates:
// Get an instance of the product object
$_product = wc_get_product( get_the_id() );
if( $_product->has_attributes() ){
// Initializing
$attributes = array();
// Loop through product attributes
foreach( $_product->get_attributes() as $taxonomy => $attribute ){
// The product attribute label name
$attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
// Set each product attribute with its values in an array
$attributes[] = '<strong>'.$attribute_name.'</strong>: '.$_product->get_attribute($taxonomy);
}
// Display (output)
echo '<div class="product-attributes"><span>'. implode( '</span> <span>', $attributes ) . '</span></div>';
}
Here, get_the_id() can be replaced by a dynamic $product_id variable (which is the post ID of a product custom post type)
I've tried on my wordpress site to group multiple products and I have no idea why but I can't add products on cart.. I've tried to complete all the input for quantity, but nothing.. Any idea? On single product works..
Here is my grouped.php
<?php
/**
* Grouped product add to cart
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.1.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $product, $post;
$parent_product_post = $post;
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<form class="cart" method="post" enctype='multipart/form-data'>
<div class="group_table">
<?php
foreach ( $grouped_products as $product_id ) :
$product = wc_get_product( $product_id );
$post = $product->post;
setup_postdata( $post );
?>
<div class="group-row">
<div class="quantity-row">
<?php if ( $product->is_sold_individually() || ! $product->is_purchasable() ) : ?>
<?php woocommerce_template_loop_add_to_cart(); ?>
<?php else : ?>
<?php
$quantites_required = true;
woocommerce_quantity_input( array( 'input_name' => 'quantity[' . $product_id . ']', 'input_value' => '0' ) );
?>
<?php endif; ?>
</div>
<div class="label">
<label>
<?php
if($product->is_visible()) {
echo '' . get_the_title() . '';
} else {
echo get_the_title();
}
?>
</label>
</div>
<?php do_action ( 'woocommerce_grouped_product_list_before_price', $product ); ?>
<div class="price">
<?php
echo ''.$product->get_price_html();
if ( $availability = $product->get_availability() ) {
$availability_html = empty( $availability['availability'] ) ? '' : '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>';
echo apply_filters( 'woocommerce_stock_html', $availability_html, $availability['availability'], $product );
}
?>
</div>
</div>
<?php
endforeach;
// Reset to parent grouped product
$post = $parent_product_post;
$product = wc_get_product( $parent_product_post->ID );
setup_postdata( $parent_product_post );
?>
</div>
<?php if($product) {?>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<?php if ( $quantites_required ) : ?>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<button type="submit" class="single_add_to_cart_button button alt"><?php echo ''.$product->single_add_to_cart_text(); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
<?php endif; ?>
<?php } else { ?>
<?php
$productid = intval( $_POST['data'] );
$product = get_product( $productid );
?>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<?php if ( $quantites_required ) : ?>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<button type="submit" class="single_add_to_cart_button button alt"><?php echo ''.$product->single_add_to_cart_text(); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
<?php endif; ?>
<?php }?>
</form>
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
UPDATE
Here is the problem fix..
woocommerce_quantity_input( array( 'input_name' => 'quantity[' . $product_id->get_id() . ']', 'input_value' => '0' ) );
The problem was at quantity.. before on quantity was all object of $product_id now is only the id of product, that was the problem..
Here is the problem fix..
woocommerce_quantity_input( array( 'input_name' => 'quantity[' . $product_id->get_id() . ']', 'input_value' => '0' ) );
The problem was at quantity.. before on quantity was all object of $product_id now is only the id of product, that was the problem..
I'm trying to figure out on how to populate my custom ordering inside my custom template page.
Here is my work in progress. So far the output shows a select box with empty values. When I check the view source i saw this error.
Warning: Invalid argument supplied for foreach() in C:\Users\Noel\Desktop\xampp\htdocs\lumiere\wp-content\themes\klasik\lumiere-products-page.php on line 23
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => 'Lumiere', 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<?php //Woocommerce Custom Ordering ?>
<form class="woocommerce-ordering" method="get">
<select name="orderby" class="orderby">
<?php foreach ( $catalog_orderby_options as $id => $name ) : ?>
<option value="<?php echo esc_attr( $id ); ?>" <?php selected( $orderby, $id ); ?>><?php echo esc_html( $name ); ?></option>
<?php endforeach; ?>
</select>
<?php
// Keep query string vars intact
foreach ( $_GET as $key => $val ) {
if ( 'orderby' === $key || 'submit' === $key ) {
continue;
}
if ( is_array( $val ) ) {
foreach( $val as $innerVal ) {
echo '<input type="hidden" name="' . esc_attr( $key ) . '[]" value="' . esc_attr( $innerVal ) . '" />';
}
} else {
echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $val ) . '" />';
}
}
?>
</form>
<li class="product product-items ">
<div class="product-item">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<div class="product-thumbnail">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
</div>
<div class="product-info">
<h3>
<?php the_title(); ?>
</h3>
<h4 class="product-category-title">
<?php
$size = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
echo $product->get_categories( ', ', '<span class="posted_in">' . ' ', '.</span>' );
?>
</h4>
<?php echo $product->get_sku(); ?>
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>
<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>
<div class="product-rating">
<?php if ($average = $product->get_average_rating()) : ?>
<?php echo '<div class="star-rating" title="'.sprintf(__( 'Rated %s out of 5', 'woocommerce' ), $average).'"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>'; ?>
<?php endif; ?>
</div>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</div>
</div>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul><!--/.products-->