How to make a default woocommerce product title? - wordpress

What I want to have is that every new product will have the default title like this: shoe Size 10
Because there will be add many products everyday it would be much easier to have that as a default product title. Does someone have a code for this or can someone help me out with this?

You can use "Secondary title plugin". Instructions on link below secondary title plugin

Try This Method
add_product( 'the_title', 'product_title');
function product_title( $title, $id ) {
if ( is_shop() && get_post_type( $id ) === 'product' ) {
return ( $title);
} else {
return $title;
}
}

Related

Add custom product option to woocommerce orders list

I am using the "custom product options" plugin and created a datepicker for customers to choose a requested ship date. I need to create a column on my orders admin page for their selection so I do not have to go into the order to find the date. I have found a few different threads that are similar but they don't really apply to my exact situation. Would someone be able to provide some help on this? Apologies for a lack of detail that is getting me downvotes, but If I knew what I needed I wouldn't be here asking what to do. I am a novice, cut me a little slack. Datepicker can be seen here.
https://chrish148.sg-host.com/product/butterscotch-oatmeal-copy/
current layout looks like this.
current layout image
This is the code that I used for one of my WooCommerce sites to get order-colors:
add_filter( 'manage_edit-shop_order_columns','shopOrder',10 );
function shopOrder($columns)
{
$columns['custom_color_column'] = "Färger";
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'populateShopOrder' );
function populateShopOrder( $column ) {
global $the_order, $post;
if( $column == 'custom_color_column' ) {
global $post, $the_order;
if ( empty( $the_order ) || $the_order->get_id() !== $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
if ( empty( $the_order ) ) {
return;
}
$items = $the_order->get_items();
foreach ($items as $item) {
// load meta data - product attributes
foreach ($item->get_meta_data() as $metaData) {
$attribute = $metaData->get_data();
// attribute value
$value = $attribute['value'];
if($value != null && $attribute['key'] == "pa_farg"){
echo "- " . $value;
if(count($items) > 1) echo "<br>";
}
else return;
}
}
}
}
However this might not be the exakt case for you. Since I do not know the exact plugin that you are using I can not know for sure.
However it should be close.
If you can figure out the attribute names then you could switch it from "fa_farg" to that, or you could link the plugin thet you are using and I will take a look at it.

Anyway to change the Total title from the WooCommerce order received page's order overview

Is there a hook to change the Total title from the WooCommerce order received page's order overview? Please see the below image to understand better
Yes, you can use the gettext WordPress filter to "translate" (rename in your case) that string of text.
Your string is inside the thankyou.php WooCommerce template:
esc_html_e( 'Total:', 'woocommerce' );
Based on WooCommerce: How to Translate / Rename Any String tutorial, the right code should be the following:
add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 9999, 3 );
function bbloomer_translate_woocommerce_strings( $translated, $untranslated, $domain ) {
if ( ! is_admin() && 'woocommerce' === $domain ) {
switch ( $translated ) {
case 'Total:':
$translated = 'Whatever:';
break;
}
}
return $translated;
}

How to conditionally use a shortcode on WooCommerce single product pages

How is it possible to hide a shortcode conditionally on WooCommerce single product pages if stock is empty?
For example if a product is out of stock:
The shortcode [scale-prices] should disappear
(A green traffic light picture changes to a yellow traffic light picture)
Your question is quite broad. But you could add a CSS body class to the product page if a product (or a variation) is out of stock. You can then use that to manipulate your page for instance via CSS or JavaScript.
The following code snippet will add out-of-stock as a body class for a simple out of stock product, and a {variation-id}-out-of-stock body class for each variation that is out of stock:
add_filter( 'body_class', 'add_class_if_product_is_out_of_stock', 10, 1 );
function add_class_if_product_is_out_of_stock( $classes ) {
if ( is_product() ) {
global $post;
if ( $product = wc_get_product( $post->ID ) ) {
if ( $product->is_type( 'variable' ) ) {
$children = $product->get_children();
foreach ( $children as $child_id ) {
if ( $product = wc_get_product( $child_id ) ) {
if ( $product->is_in_stock() == false ) {
$classes[] = sprintf( '%s-out-of-stock', $child_id );
}
}
}
} elseif ( $product->is_in_stock() == false ) {
$classes[] = 'out-of-stock';
}
}
}
return $classes;
}
This snippet should be added to the functions.php of your child theme or via a plugin like Code Snippets.
You can use any of these single product page hooks and add a condition of your need.
https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/
Like you can use woocommerce_before_single_product and check for product availablity and based on that result you can use add_shortcode, remove_shortcode. Also you can add script using wp_footer script if required.
You can share further details/scenario for exact solution.

Rename the post title with media name - Wordpress

I have a wordpress website with customs posts and metas boxes.
One of these manage some pictures and I want to force the title of the post.
It should be the same as the name of the media uploaded.
Is it possible ? And how ?
Thank's
Manipulate the post title with a filter.
function change_post_title( $title, $id = null ) {
if ( is_single() ) {
$title = 'new title';
}
return $title;
}
add_filter( 'the_title', 'change_post_title', 10, 2 );
Thanks all for your help.
I have used a filter but this one :
function modify_post_title($data){
if($data['post_type'] == 'fcfm_photos' && isset($_POST['image'])) {
$data['post_title'] = substr($_POST['image'], -(strpos(strrev($_POST['image']),'/')));
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 );
And when I save the post, the post title change automatically. This is what i want.

WooCommerce inquiry if no price available

I'm helping a good friend setting up a WooCommerce shop. Since the shop is going to be bigger and the products are pretty variable and customizable we are not able to provide/configure all prizes from the beginning.
However we would like all products to be in the shop and ad an inquiry lead form in case no price is available.
Since I never programmed with WooCommerce I was wondering that is the right hook to implement such an functionality?
Had the exact same issue and couldn't find a plugin or a solution anywhere so I figured a workaround myself:
You need to edit file
/wp-content/themes/your-theme-name/woocommerce/single-product/add-to-cart/simple.php
(if it's not there just copy it from woocommerce plugin
/wp-content/plugins/woocommerce/templates/single-product/add-to-cart/simple.php)
and on line 14 where it says
if ( ! $product->is_purchasable() ) return;
you need to comment it out and write something like
if ( ! $product->is_purchasable() ) {
// put your code here
return;
}
and in the //put your code here line you can enter for example a shortcode for a form or a more complicated solution would be to put code for a button that when clicked will open up a popup form.
Still working on that ;)
Maybe too late, but I have had same issue currently.
Here is there code, Woocommerce uses to check if a product can be purchased:
https://github.com/woocommerce/woocommerce/blob/master/includes/abstracts/abstract-wc-product.php#L1404
Notice about: && '' !== $this->get_price()
/**
* Returns false if the product cannot be bought.
*
* #return bool
*/
public function is_purchasable() {
return apply_filters( 'woocommerce_is_purchasable', $this->exists() && ( 'publish' === $this->get_status() || current_user_can( 'edit_post', $this->get_id() ) ) && '' !== $this->get_price(), $this );
}
So you need to write a filter like this to override default:
add_filter( 'woocommerce_is_purchasable', function ( $is_purchasable, $product ) {
return $product->exists() && ( 'publish' === $product->get_status() || current_user_can( 'edit_post', $product->get_id() ) );
}, 10, 2 );
Try the following code snippet. You just have to put it in your functions.php. You don't need a plugin or to overwrite WooCommerce files in your child theme.
// Inquiry link if no price available
function add_inquiry_link_instead_price( $price, $product ) {
if ( '' === $product->get_price() || 0 == $product->get_price() ) :
return ''.__( 'Jetzt anfragen' ).'';
endif;
}
add_filter( 'woocommerce_get_price_html', 'add_inquiry_link_instead_price', 100, 2 );

Resources