Create custom layout product list woocommerce - woocommerce

I want to make a list of products woocommerce as warungssl..com shown are: the product name, normal price, discount prices, some attributes, link or button that leads to a product detail page, and a link or button cart.
In Which file should I change the script code and I do not understand how to display multiple attributes.
Note:
1. To (issuance, validation, and site seal) I will call the attribute
data. The obstacles I did not understand the script.
2. I make use of Wordpress themes porto
3. The following examples are meant attributes
Maybe it could let me know where the location of the files that I have to change.

please go to here : wp-content\plugins\woocommerce\templates\archive-product.php
or
please go to here : wp-content\themes\porto\woocommerce\archive-product.php
and put following code:
<?php
global $product;
$greenbar = $product->get_attribute( 'greenbar' );
$issuance = $product->get_attribute( 'issuance' );
$mobile_friendly = $product->get_attribute( 'mobile_friendly' );
$san_support = $product->get_attribute( 'san_support' );
$site_seal = $product->get_attribute( 'site_seal' );
$validation = $product->get_attribute( 'validation' );
$warranty = $product->get_attribute( 'warranty' );
?>

Related

WooCommerce - Open the new product that the category is selected

I've been searching all over the internet for hours how to automatically assign a category to new products. When you open the new product that the category is selected.
I have two product categories (Books and FIlms) and I would like that every time we open a new product, Books are selected. In this way it will directly show the custom fields of that product category and we will speed up the creation process.
It's possible?
thanks
UPDATE
I found a code that seems to work with the posts. Any idea how I can adapt the code for products and where should I put the category I care about?
https://wordpress.stackexchange.com/questions/243462/automatically-select-categories-on-new-post-based-on-get-value
When it comes to the checkbox that should already be checked when creating a new product, you can use jQuery
Replace in-product_cat-15 with in-product_cat-{YOUR-CAT-ID}
// Define the admin_head callback
function action_admin_head() {
global $post, $pagenow;
// Only on new product pages
if( $pagenow != 'post-new.php' ) return;
?>
<script>
jQuery(function($){
$( '#in-product_cat-15' ).attr( 'checked', true );
});
</script>
<?php
}
add_action( 'admin_head', 'action_admin_head', 10, 0 );
In product categories click the Make default action of your desired category to make it as default category. For more details refer the image:
You can visit this page using this URL (replace the domain with your domain):
www.example.com/wp-admin/edit-tags.php?taxonomy=product_cat&post_type=product

How to set a WooCommerce email template as default for all emails

I’m looking for a way to send all WordPress emails using a custom WooCommerce template so all emails will look the same.
The path to the template would be:
woocommerce/emails/my-custom-woocommerce-template.php
Does it have to all be templatized in a single file? If not, a combination of these entry points can probably get you the standardization you're looking for:
email-header.php lets you customize the start of the email including the header image (if you need to do more than change its URL). It opens the layout tags for the rest of the email content
email-footer.php lets you customize the footer, and closes the layout tags started in the header.
email-styles.php or the woocommerce_email_styles filter let you customize the CSS (see some gotchas in my article here).
Various actions/filters are scattered throughout the emails for customizing individual parts.
You can use the below function. It is working
function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
// List of all templates that should be replaced with custom template
$woo_templates = array(
'emails/admin-new-order.php',
'emails/admin-failed-order.php',
'emails/admin-cancelled-order.php',
'emails/customer-completed-order.php',
'emails/customer-new-account.php',
'emails/customer-note.php',
'emails/customer-on-hold-order.php',
'emails/customer-processing-order.php',
'emails/customer-refunded-order.php',
'emails/customer-reset-password.php',
);
//Check whether template is in replacable template array
if( in_array( $template_name, $woo_templates ) ){
// Set your custom template path
$template = your_template_path.'emails/my-custom-woocommerce-template';
}
// Return what we found
return $template;
}
add_filter( 'woocommerce_locate_template', 'myplugin_woocommerce_locate_template', 10, 3 );
add_filter( 'wp_mail', 'your_wp_mail_action' ); // $args = compact( 'to', 'subject', 'message', 'headers', 'attachments' )
function your_wp_mail_action( $args ) {
global $your_prefix_your_email_args; // the args you could use in my-custom-woocommerce-template file
$your_prefix_your_email_args = $args;
ob_clean();
get_template_part( 'woocommerce/emails/my-custom-woocommerce-template' );
$args['message'] = ob_get_clean();
// ... your logic
return $args;
}
To view and update email settings, log into your website dashboard. In the left-hand menu, click on WooCommerce → Settings.
There, you’ll find several options tabs at the top. Click Emails to view the following templates
you can custom all as you want

How to get a Product Variation Custom Field to work along other plugins?

I get this code (see below) to create a Product Variation Custom Field. It works just fine. Now I need to use the WP All Import Pro plugin to import Products from a csv file. This plugin allow to create the importation task by mapping the information in the csv to the fields of Product and Product Variation.
Problem: thing is that the new created Product Variation Custom Field is not visible for the WP All Import plugin. I mean, this new field is not listed when I do the mapping of the data be imported.
My assumption is that this code fails to create some data in the database to make this field available for other module.
How can I get this to work properly
I also attached a capture of the WP All Import page where the field should be visible.
/*******************************
add custom fields to product variations
*********************************/
// regular variable products
add_action( 'woocommerce_product_after_variable_attributes', 'add_to_variations_metabox', 10, 3 );
add_action( 'woocommerce_save_product_variation', 'save_product_variation', 20, 2 );
/*
* Add new inputs to each variation
*
* #param string $loop
* #param array $variation_data
* #return print HTML
*/
function add_to_variations_metabox( $loop, $variation_data, $variation ){
$custom = get_post_meta( $variation->ID, '_custom', true ); ?>
<div class="variable_custom_field">
<p class="form-row form-row-first">
<label><?php echo __( 'MY CUSTOM FIELD:', 'plugin_textdomain' ); ?></label>
<input type="text" size="5" name="variation_custom_data[<?php echo $loop; ?>]" value="<?php echo esc_attr( $custom ); ?>" />
</p>
</div>
<?php
}
/*
* Save extra meta info for variable products
*
* #param int $variation_id
* #param int $i
* return void
*/
function save_product_variation( $variation_id, $i ){
// save custom data
if ( isset( $_POST['variation_custom_data'][$i] ) ) {
// sanitize data in way that makes sense for your data type
$custom_data = ( trim( $_POST['variation_custom_data'][$i] ) === '' ) ? '' : sanitize_title( $_POST['variation_custom_data'][$i] );
update_post_meta( $variation_id, '_custom', $custom_data );
}
}
WP ALL IMPORT has this section coded into their files. They have not provide any hook or filter to add fields to this section.
The most important thing here is that WP ALL IMPORT has thought is like this :
As all the Meta for a particular variation is added finally to the post meta table. Which will be retrieved as by get_post_meta. Just like the custom fields. So in order to attach meta to the variation, you can just another Custom Fields with the Name as the name which the actual meta is stored with and with the value you want the variation to be. Just check the image attached. Refer - http://www.wpallimport.com/documentation/custom-fields/theme-plugin-fields/
I know this question was asked almost a year ago but I have been trying to figure out this exact issue out for quite some time now. But in the end I managed to find a workaround that at least will allow you to get that data into the variation instead of the main parent product:
1) In the WpAllImport Wordpress Addon you will be able to see a "variations" tab as shown in your screenshot. Click on this.
2) On this page you will once again not be able to see any custom fields you have made for variations HOWEVER there is a product attributes section.
3) If you add your variation as an attribute and uncheck "Show in variations" and "Taxonomy" and "Is Visible" then you can store your data in an attribute.
4) After the import you should be able to see you data in the attribute, if you know some programming you can even write a script to then loop through all variations and copy this data over to a custom field.
I know it's not much, but for my purposes I was at least able to save the data in the variation which I then used late in a product export plugin.
Hope that helps!
Though this question was initially asked 2 years ago. I found a solution in 2020. I hope this will help anyone who's still looking for a solution.
Please go to All Products and at the top where it says Add New Product you should see two more buttons "Import" and "Export". Click on Export and you will see an option of checkbox "Yes, export all custom meta" Please check this potion and all your custom fields even in variations will be exported.
Thanks

Woocommerce get product Size in Email Template

I am creating a email template and I am trying to get the size of the product. I have tried the following, but it retrieves all the sizes:
echo nl2br( $_product->get_attribute( 'size' ) );
The code above did work for color. Any ideas?
Your question is not clear about the problem. You should add few more
details, "are you trying to do outside of woocommerce loop?" and "are
you getting any error message?"
Anyway, you can get any custom attributes value by following code:
$product->get_attribute( 'your_attr' );
If your products custom attribute name is size, you can use as following:
global $product;
echo nl2br( $product->get_attribute( 'size' ) );
It should work. Thank you.

How to Add Attribute Terms Image in WooCommerce?

In WooCommerce, I have created an attribute "Brand", and added some terms, like "Brand One", "Brand Two" etc..
I want to add an image for each term.
Right now there is no option to add image in attribute terms.
Please tell me how to add image in attribute terms.
An admin link is like this:
.../wp-admin/edit-tags.php?taxonomy=pa_brand&post_type=product'
WooCommerce stores product attributes outside of the usual taxonomy table, so you'll need to go with something more WC-specific. Try the Variation Swatches and Photos extension.
UPDATE: You can use the Taxonomy Images plugin but you have to make a minor alteration. By default the plugin only displays taxonomies that are set to display in the admin area (i.e. the show_ui value is set to true). WooCommerce hides the product attribute taxonomies by default, so the plugin will not display them in the settings screen. You can change this behaviour by commenting out/deleting lines 402-402 of taxonomy-images.php:
if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) )
continue
Removing these lines will allow he plugin to display all taxonomies, regardless of whether they are hidden or not.
Props to #helgatheviking for suggesting that plugin in the first place
With the "Variation Swatches" plugin (see the answer by #Dre), everything works smoothly, and getting the image is as easy as this:
$swatch_term = new WC_Swatch_Term( 'swatches_id', $term_id, $taxonomy, false,
'swatches_image_size' );
$html = '<img src="' . $swatch_term->thumbnail_src . '" alt=""/>';
The "Taxonomy Images" has not been updated since WP 3.6.1...
Technically a WooCommerce "attribute" is just a WordPress Custom Taxonomy. Therefore I would try something like the Taxonomy Images plugin.
"Variation Swatches and Photos extension" plugin is premium and no body would like to purchase that to serve such a purpose as getting an icon image for a brand.
The "Taxonomy Images" has not been updated since WP 3.6.1...
What I came up with is Category and Taxonomy Image and that does the job.
Here's how you can get the image URL:
if (function_exists('get_wp_term_image'))
{
$meta_image = get_wp_term_image($term_id);
//It will give category/term image url
}
echo $meta_image; // category/term image url
I've fixed this issue. Actually i was not passing the right value in taxonomy. I was using variation swatches plugin so was not know which value to pass for taxonomy. below is the working code. I was trying to fetch "brands" attributes list with images.
$attribute_taxonomies = wc_get_attribute_taxonomies();
$taxonomy_terms = array();
if ($attribute_taxonomies) :
foreach ($attribute_taxonomies as $tax) :
if (taxonomy_exists(wc_attribute_taxonomy_name($tax->attribute_name))) :
if($tax->attribute_name=="brands"){
$taxonomy_terms[$tax->attribute_name] = get_terms(wc_attribute_taxonomy_name($tax->attribute_name), 'number=6&orderby=name&hide_empty=1');
}
endif;
endforeach;
endif;
foreach ($taxonomy_terms as $item) :
foreach($item as $child):
//print_r($child);
$thumbnail_id = get_woocommerce_term_meta( $child->term_id, 'product_pa_brands', true );
$textureImg = wp_get_attachment_image_src( $thumbnail_id );
//we are getting image in $textureImg[0]
}
endforeach;
endforeach;

Resources