I have in txt file this data for products of shop :
product 1
product 1
product 2
product 2
product 2
product 1
product 1
product 3
product 3
product 3
product 1
product 1
product 3
product 1
Ok , the people add products to the card of shopping and these products insert in general txt
For recover the data i use the next script :
<?php
$file_data=file("products.txt");
for ($i=0;$i<sizeof($file_data);$i++)
{
/// Create array of groups
$global_products[]=$file_data[$i];
}
/// Now i want get the products and the number in each case for example of the product 1 i have 6 for the product 2 i have 3 and for the product 3 i have 4 , ok for get this i can use thi function
$prr=array_count_values($global_productos);
print_r (object2array($prr),true);
?>
If i use print_r i can get the products and number in each case but how i can get in other mode , for example for use with normal function of print or echo , i try get finally the data show as this :
Product 1 (6)
Product 2 (3)
Product 3 (4)
Thank´s Regards
use the code below
<?php
$file_data=file("output_rrr.txt");
for ($i=0;$i<sizeof($file_data);$i++)
{
/// Create array of groups
$global_products[]=$file_data[$i];
}
/// Now i want get the products and the number in each case for example of the product 1 i have 6 for the product 2 i have 3 and for the product 3 i have 4 , ok for get this i can use thi function
$prr=array_count_values($global_products);
foreach($prr as $key=>$value)
{
echo trim($key).": ".$value."<br/>";
}
?>
Related
I have around 4000 categories in WooCommerce and I don't have the time to go through every category and manually update the category descriptions. I am wondering if it would be possible to output a generic category description based on the H1 tag?
For example:
if the title is 'Ford Focus Car Spares'
The category description would autofill to something like:
'Buy Ford Focus Car Spares - We stock a huge range of Ford Car Spares'
I would need a way of programmatically removing the keywords from the h1 title and outputting them into the description.
Thankyou to anybody that can help.
You can hook the display of the title of your category page
add_action( 'woocommerce_archive_description', 'custom_category_description', 10, 2);
function custom_category_description($woocommerce_taxonomy_archive_description, $int) {
if ( is_product_category()) {
$title_cat = get_the_title($int);
echo 'Buy '.$title_cat.' - We stock a huge range of '.$title_cat;
}
}
I haven't tested this part of code but this is what I will explore
I have same product linked to different sub-category and I need save them separately and not adding in to cart/checkout etc…
I think the good way is to save them with variation named "category_name" with value [$product_category] to differentiate them in the loop and showing them in the cart/checkout pages like in this example :
Room_1 (main category)
Wall_works (subcategory)
Cleaning_windows hours Q.ty 4 (product)
———————————————————————————————————————
Room_2 (main category)
Wall_works (subcategory)
Cleaning_windows hours Q.ty 8 (product)
———————————————————————————————————————
Room_3 (main category)
Wall_works (subcategory)
Cleaning_windows hours Q.ty 8 (product)
And NOT like now as this (in 1 line):
Cleaning_windows hours Q.ty 20
I found online, this snippet for retrieving the main_category name but I dont know how use and save the value, and how to show it in cart/checkout like in my example above:
// retrieve category name
function get_product_category_by_id( $category_id ) {
$term = get_term_by( 'id', $category_id, 'product_cat', 'ARRAY_A' );
return $term['name'];
}
$prod_terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($prod_terms as $prod_term) {
// gets product cat id
$product_cat_id = $prod_term->term_id;
// gets an array of all parent category levels
$product_parent_categories_all_hierachy = get_ancestors( $product_cat_id, 'product_cat' );
// This cuts the array and extracts the last set in the array
$last_parent_cat = array_slice($product_parent_categories_all_hierachy, -1, 1, true);
foreach($last_parent_cat as $last_parent_cat_value){
// $last_parent_cat_value is the id of the most top level category, can be use whichever one like
}
}
$product_category = get_product_category_by_id( $last_parent_cat_value );
I need to create product variation with value => $product_category saved by default in all products when added to cart, without creating/inserting variations for all products (when created in back end) and without showing this variation in simple product page (front end).
How can I achieve this?
Thanks in advance for all help.
There are 3 categories in my Neto store:
Category 1
Category 2
Category 3
I want to display ONLY one category i.e Category 2(Specific category) on the Homepage.
Anyone Know How can i achieve this.
Thanks in advance
use this code and apply according to you choice
[%thumb_list type:'products' filter_category:'' limit:'10'%]
[%param template%]
[%if [#name#] eq 'Shirts'%]
shirt_template
[%else%]
default`enter code here`
[%/if%]
[%/param%]
I have a url like this
http://example.com/index.php?&item_name_1=productnamex&quantity_1=1&amount_1=0&item_number_1=2&on0_2=thumb&option_index_2=1&item_name_2=productnamex&quantity_2=1&amount_2=0&item_number_2=2&on0_2=thumb&option_index_2=1&item_name_3=productnamexx&quantity_3=1&amount_3=0&item_number_3=3&on0_3=thumb&option_index_3=1.....
that sends to a page the values of a shopping card. I want to GET the values item_name_x, quantity_x, amount_x where x the number of each product, group and print them like
Product 1 name - Product 1 Quantity - Product 1 Amount
Product 2 name - Product 2 Quantity - Product 2 Amount
Product 3 name - Product 3 Quantity - Product 3 Amount......
I can't make any change to the page who produce the url.
Can anyone help me?
Thanks in advance for any help you are able to provide.
That's a really bad design, poor you have to deal with it. However, if you're sure that the query string will always be consistent (i.e.: each group will always be complete: name-quantity-amount) you can try this:
$i = 1;
while (isset($_GET['item_name_'.$i])) {
$name = $_GET['item_name_'.$i];
$qty = $_GET['quantity_'.$i];
$amt = $_GET['amount_'.$i];
... // do whatever you want with those 3
$i++;
}
what about this
<?php
$count=count($_GET);
for($i=1;$i=$count;$i++)
{?>
Product <?php $i;?> name - Product <?php echo $i?> Quantity - Product <?php echo $i?> Amount
<?php }?>
I have toons of products in a magento store thats need to be
sorted into new categories based on diffrent attributes any
one knows how to do this with a script.
example:
if the product attribute "COLOR" has a value of Blue the product should be in cat 10
and so on
Once you iterate over your products you can use the setCategoryIds method (this code is meant to be used for a dropdown attribute as it uses the getAttributeTextMethod):
$product->load($productId);
if( strcmp($product->getAttributeText('COLOR') , 'Blue') == 0 ){
$product->setCategoryIds(array('cat1Id' ,'cat2Id'));
}
$product->save();