wordpress multiple select in theme option page - php

im trying to make this work. its theme option page that list categories and allow you to do MULTIPLE select
but something is wrong and it not saving the values and in the end how can i show these selected categories in index?
here is what i found in web and sof
<?php
add_action( 'admin_init', 'theme_options_init' );
add_action( 'admin_menu', 'theme_options_add_page' );
function theme_options_init(){
register_setting( 'sample_options', 'sample_theme_options', 'theme_options_validate' );
}
function theme_options_add_page() {
add_theme_page( __( 'Theme Options', 'sampletheme' ), __( 'Theme Options', 'sampletheme' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
}
function theme_options_do_page() {
global $select_options, $radio_options;
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false;
?>
<div class="wrap">
<?php screen_icon(); echo "<h2>" . get_current_theme() . __( ' Theme Options', 'sampletheme' ) . "</h2>"; ?>
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e( 'Options saved', 'sampletheme' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( 'sample_options' ); ?>
<?php $options = get_option( 'sample_theme_options' ); ?>
<select multiple="multiple" name="site_options[categorychoice][]">
<?php $option = get_option('site_options'); ?>
<?php
$args = array(
'orderby' => 'name',
'parent' => 0,
'exclude' => 1
);
$categories = get_categories( $args );
foreach ($categories as $category) { ?>
<?php $selected = in_array( $category->cat_ID, $option['categorychoice'] ) ? ' selected="selected" ' : ''; ?>
<option value="<?php echo $category->term_id; ?>" <?php echo $selected; ?> >
<?php echo $category->cat_name . ' (' . $category->category_count .')'; ?>
</option>
<?php } //endforeach ?>
</select>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'sampletheme' ); ?>" />
</p>
</form>
</div>
<?php
}
function theme_options_validate( $input ) {
global $select_options, $radio_options, $categories;
if ( ! array_key_exists( $input['categorychoice'], $categories ) )
$input['categorychoice'] = NULL;
return $input;
}

Related

Display Woocommerce product attributes in a custom single post

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)

Getting POST data from SELECT dropdown with variable value

I need to create as many dropdowns as values from a database table query in worpress. I can't get post data to usermeta table from foreach dropdown list . This is the code:
$custom_posts_type = $wpdb->get_results("SELECT label,id FROM $table_name");
foreach ($custom_posts_type as $custom_post_type) {
$custom_post_type_name = $custom_post_type->label;
$custom_post_type_id = $custom_post_type->id;
?>
<p>
<label for="dropdown">Permisos de usuario para <?php echo $custom_post_type_name;?>: </label>
<?php
$user_custom_post = 'user_custom_' . $custom_post_type_name;
$selected = get_the_author_meta( $user_custom_post, $user->ID );
$post_type_object = get_post_type_object($custom_post_type_name);
$label = $post_type_object->label;
$posts = get_posts(array('post_type'=> $custom_post_type_name, 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1));
echo '<select name="' . $user_custom_post . '" id="' . $user_custom_post . '">';
?>
<option value="all" <?php selected( $user_custom_post[0], "all" ); ?>>All <?php echo $label;?></option>
<?php
foreach ($posts as $post) {
echo '<option value="', $post->ID, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>';
}?>
<?php
echo '</select>';
?>
</p>
<?php
update_user_meta( $user->ID, $user_custom_post, $_POST[$user_custom_post] );
} //endforeach
I appreciate your help.
Thks
Probably... I have created two functions without foreach. And, if I don't use variables it works:
add_action( 'show_user_profile', 'pglr_user_pages' );
add_action( 'edit_user_profile', 'pglr_user_pages' );
add_action( 'user_register', 'pglr_user_pages' );
function pglr_user_pages( $user ) {
$post_type = "page"; ?>
<p>
<label for="dropdown">Asignar <?php echo $post_type;?>: </label>
<?php
$selected = get_the_author_meta( 'user_custom_page', $user->ID );
$post_type_object = get_post_type_object($post_type);
$label = $post_type_object->label;
$posts = get_posts(array('post_type'=> $post_type, 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1));
echo '<select name="user_custom_page_value" id="user_custom_page_value">';
?>
<option value="all" <?php selected( '', "all" ); ?>>All <?php echo $label;?></option>
<?php
foreach ($posts as $post) {
echo '<option value="', $post->ID, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>';
}?>
<?php
echo '</select>';
?>
</p>
<?php
}
add_action( 'personal_options_update', 'save_pglr_user_pages' );
add_action( 'edit_user_profile_update', 'save_pglr_user_pages' );
function save_pglr_user_pages( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
//save dropdown
update_usermeta( $user_id, 'user_custom_page', $_POST['user_custom_page_value'] );
}
However, this code doesn't work:
add_action( 'show_user_profile', 'pglr_user_pages' );
add_action( 'edit_user_profile', 'pglr_user_pages' );
add_action( 'user_register', 'pglr_user_pages' );
function pglr_user_pages( $user ) {
$post_type = "page"; ?>
<p>
<label for="dropdown">Asignar <?php echo $post_type;?>: </label>
<?php
**global $user_custom_post;**
**$user_custom_post = 'user_custom_' . $post_type;**
$selected = get_the_author_meta( **$user_custom_post**, $user->ID );
$post_type_object = get_post_type_object($post_type);
$label = $post_type_object->label;
$posts = get_posts(array('post_type'=> $post_type, 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1));
echo '<select name="user_custom_page_value" id="user_custom_page_value">';
?>
<option value="all" <?php selected( '', "all" ); ?>>All <?php echo $label;?></option>
<?php
foreach ($posts as $post) {
echo '<option value="', $post->ID, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>';
}?>
<?php
echo '</select>';
?>
</p>
<?php
}
add_action( 'personal_options_update', 'save_pglr_user_pages' );
add_action( 'edit_user_profile_update', 'save_pglr_user_pages' );
function save_pglr_user_pages( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
//save dropdown
update_usermeta( $user_id, **$user_custom_post,** $_POST['user_custom_page_value'] );
}
The problem may be using variables...

Can't add to cart grouped products

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..

How to use Metabox checkbox to add page ids in array?

What I'm trying to do is for a dual-language website. This particular language, Papiamento, isn't supported by Wordpress. Therefore, the client had to create two separate pages, in English and Pap. What I did was to code it like that to display English or Pap menu for each page.
Like this, in header.php:
<?php
if( is_page( array('salon-and-spa-pap', 'tocante-nos', 'testimonio', 'tuma-contacto-cu-nos', 'galeria', 'tratamentonan-di-masahe', 'tratamentonan-spa-di-curpa', 'servicionan-di-boda', 'tratamentonan-spa-di-cara', 'wowo-lip-nek', 'cuido-di-man', 'tratamento-di-huna', 'tratamento-di-huna-di-pia', 'cuido-di-pia', 'salon-p', 'spa-etiquette-pap', 'wax-p', 'reserva-un-tratamento')) ) {
wp_nav_menu(array( 'theme_location' => 'menu_top_pap' ) );
} else {
wp_nav_menu(array( 'theme_location' => 'secondary-menu' ) );
}
?>
However, the problem is that the client will have to keep going back to header.php to add another page slug every time she create a new page. Therefore, I created a Metabox plugin for that. I made a Metabox checkbox so that everytime a page is intended for Papiamento language, the client can just check the box and either the page id or slug will be added to the code above.
I found another question (https://wordpress.stackexchange.com/questions/71043/listing-pages-with-checkboxes-in-a-metabox-and-saving-them) that might be similar to what I was looking for but it didn't work for me.
Here's my metabox function based on this article (http://themefoundation.com/wordpress-meta-boxes-guide/).
<?php
function prfx_custom_meta() {
add_meta_box( 'prfx_meta', __( 'Papiamento Page Box', 'prfx-textdomain' ), 'prfx_meta_callback', 'page', 'normal', 'low' );
}
add_action( 'add_meta_boxes', 'prfx_custom_meta' );
function prfx_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
$prfx_stored_meta = get_post_meta( $post->ID );
$checkfield = maybe_unserialize( get_post_meta($post->ID, "checkfield", true) );
?>
<p>
<span class="prfx-row-title"><?php _e( 'Pap Checkbox', 'prfx-textdomain' )?></span>
<div class="prfx-row-content">
<label for="meta-checkbox">
<input type="checkbox" name="checkfield[]" id="page_<?php echo $page->ID; ?>" value="<?php echo $page->ID; ?>" <?php if ( in_array($page->ID, (array) $checkfield) ) { ?> checked <?php } ?>/> <label for="page_<?php echo $page->ID; ?>"><?php echo $page->post_title; ?>
<?php _e( 'Check if this page is Papiamento', 'prfx-textdomain' )?>
</label>
</div>
</p>
<?php
}
/**
* Saves the custom meta input
*/
function prfx_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and sanitizes/saves if needed
// Checks for input and saves
if( isset( $_POST[ 'checkfield' ] ) ) {
update_post_meta($post_id, "checkfield", $_POST['checkfield'] );
}
}
add_action( 'save_post', 'prfx_meta_save' );
and calling the page id in header.php like this:
<?php
if( in_array($page->ID, (array) $checkfield) ) {
wp_nav_menu(array( 'theme_location' => 'menu_top_pap' ) );
} else {
wp_nav_menu(array( 'theme_location' => 'secondary-menu' ) );
}
?>
But it didn't work. Please help!
***************** UPDATE *****************
I've been trying to edit the function prfx_meta_callback( $post ) but with no success. Here's the latest code I'm trying to modify...
function prfx_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
$checkfield = maybe_unserialize( get_post_meta($post->ID, "checkfield", true) );
$page = get_pages();
$prfx_stored_meta = get_post_meta( $post->ID );
?>
<p>
<span class="prfx-row-title"><?php _e( 'Pap Checkbox', 'prfx-textdomain' )?></span>
<div class="prfx-row-content">
<label for="page_<?php echo $page->ID; ?>">
<input id="page_<?php echo $page->ID; ?>" type="checkbox" name="checkfield[]" value="<?php echo $page->ID; ?>" <?php if ( isset($checkfield [ ?>'<?php echo $page->ID; ?>'<?php ] ) ) checked( $checkfield[ ?>'<?php echo $page->ID; ?>'<?php ][0], '<?php echo $page->ID; ?>'); ?>/> <?php _e( 'Check if this page is Papiamento', 'prfx-textdomain' )?></label> <br>
</div>
</p>
<?php
I've been trying to make it like that, if Pap, then checked, but if not Pap, unchecked in every page.
If the metabox is saving the checkbox settings properly, you can use the following code to make the check in header.php:
if ( in_array( get_the_ID(), get_post_meta( get_the_ID(), 'checkfield', true ) ) ) {
wp_nav_menu(array( 'theme_location' => 'menu_top_pap' ) );
} else {
wp_nav_menu(array( 'theme_location' => 'secondary-menu' ) );
}

Populate Custom Ordering/Sorting woocommerce

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-->

Categories