Woocommerce custom checkout page per product [closed] - wordpress

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a woocommerce product which requires different fields than the others.
Is there a way to have a custom checkout page specifically for this product?

You can not have custom checkout page for specific product. However, you can customize checkout fields dynamically based on product in your cart.
// Override fields like this
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['order']['order_comments']['placeholder'] = 'My new placeholder';
$fields['order']['order_comments']['label'] = 'My new label';
return $fields;
}
// Remove fields like this
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
unset($fields['order']['order_comments']);
return $fields;
}
You can find more details on how to customize woocommerce checkout fields here: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

Related

hide the price for protected products in shop page WooCommerce [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 months ago.
Improve this question
how to hide the price for protected products in shop page WooCommerce ?
To hide the price for protected products you can add a filter for displaying the price html and check if the product is protected, by checking to see if a password has been set, and if so return no value.
add_filter( 'woocommerce_get_price_html', 'hide_protected_product_price', 10, 2 );
function hide_protected_product_price( $price, $product ) {
if ( ! empty( $product->get_post_password() ) && ! is_single() ) {
return '';
}
return $price;
}
"Protected:" is added by WordPress not WooCommerce. To replace "Protected:" with "Reserved:" you need to add the protected_title_format filter. To make sure you only do it for products, first check the post_type
function jt_replace_product_protected_text( $prepend ) {
global $post;
if ( $post->post_type == 'product' ) {
return __( 'Reserved: %s' );
}
return $prepend;
}
add_filter( 'protected_title_format', 'jt_replace_product_protected_text' );

Filter products by category on Woocommerce [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to filter all products of the category shirts to add a custom field on all shirts. Because I don't want to add that custom field in the rest products. So I want the custom field visible on product page, cart and checkout.
You can use the following filter to filter the item name on the cart and checkout: woocommerce_after_cart_item_name
To add something to your product page you can choose from a variety of actions to hook into. Here is a visual overview.
In the following example I've chosen to add something before the add to cart form on the product page.
add_action( 'woocommerce_before_add_to_cart_form', 'product_page_show_field_based_on_category', 10 );
function product_page_show_field_based_on_category() {
global $product;
if ( has_cat( $product->get_category_ids() ) ) {
echo "<p>Has category Shirt</p>";
}
}
add_filter( 'woocommerce_cart_item_name', 'checkout_and_cart_show_field_based_on_category', 10, 3 );
function checkout_and_cart_show_field_based_on_category( $product_name, $cart_item, $cart_item_key ) {
if ( has_cat( $cart_item['data']->get_category_ids() ) ) {
$product_name .= "<p>Has category Shirt</p>";
}
return $product_name;
}
function has_cat( $cat_ids ) {
$cat_id = 1; //set your shirt category id here
return in_array( $cat_id, $cat_ids) ? true : false;
}
Both filter and action make use of a small helper function to check for the category id.

I want to hide woocommerce products from the shop loop which the user already puchased [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to hide those products from the shop loop which user already purchased
hey you can use this to hide or remove the product from the shop that is already purchased
add_action( 'woocommerce_after_shop_loop_item', 'user_logged_in_product_already_bought', 30 );
function user_logged_in_product_already_bought() {
if ( is_user_logged_in() ) {
global $product;
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->get_id() ) )
?>
<script>
var productId = '<?= $product->get_id(); ?>';
jQuery(document).ready(function(){
jQuery(".products li .post-"+productId).remove();
});
</script>
<?php
}
}
Yes you can use the below wc_customer_bought_product function to set the condition for your requirement.
First You have to refer below function code.
https://docs.woocommerce.com/wc-apidocs/function-wc_customer_bought_product.html

WooCommerce how to change the "return to shop" button text? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I can change the button link using the woocommerce_return_to_shop_redirect hook, but i cannot find a "nice" way to change the button text.
I would avoid modifying the core file wp-content/plugins/woocommerce/templates/cart/cart-empty.php every time woocommerce gets updated.
Any other ideas?
Thanx.
You can do it this way. I have changed 'shop' to 'store' in the following example.
add_filter( 'gettext', 'change_woocommerce_return_to_shop_text', 20, 3 );
function change_woocommerce_return_to_shop_text( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Return to shop' :
$translated_text = __( 'Return to Store', 'woocommerce' );
break;
}
return $translated_text;
}

Show brand on woocommerce product page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i would like to have woocommerce display the brand of the product under product information on each product
is that possible?
Thanks in advance
Morten
wordpress 3.9.1
woocommerce 2.1.10
The following will work on a WooCommerce single product page.
The easiest way is to create a WooCommerce Product Category called "Brands" and list your brands as sub-categories.
-Brands
--Apple
--Microsoft
--Google
You'd check the brand category "Apple" to your product, for example. Skip checking "Brands" however.
Next you need a hook that will display the checked sub-category of "Brands" under you product.
One such hook is: woocommerce_after_single_product()
There are others here - the WooCommerce hook reference
In your functions.php file or plugin, add the following code.
add_action('woocommerce_after_single_product', 'my_woocommerce_after_single_product' );
function my_woocommerce_after_single_product () {
global $product;
$taxonomy = 'product_cat';
$slug = 'brand'; //Or whatever the slug of "Brand" is
$term = get_term_by('slug', $slug, $taxonomy);
//Gets the ID of the Parent category
$term_id = $term->term_id;
//Get the Child terms
$brand_terms = wp_get_post_terms( $product->id, $taxonomy, array("fields" => "all") );
foreach ($brand_terms as $brand_item) {
// Hunt out the child term that is a child of the parent
if ( $brand_item->parent == $term_id ) {
//Get the name of the brand
$brand = $brand_item->name;
break; //Assumes you've only assigned one Brand
}
}
echo '<p>The Brand is: ' . $brand; //Apple or Microsoft or Google...
}
(If it works, please mark it as "Answered")

Resources