How to display a custom product field value of a specific category on a Woo Commerce checkout page?

Try something like this, I am unable to test this at the moment. add_action(‘woocommerce_before_calculate_totals’, ‘personalization_check_category_in_cart’); function personalization_check_category_in_cart() { // loop through all products in the Cart foreach (WC()->cart->get_cart() as $cart_item) { // if cart has category term, set variable $cat_in_cart to true if (has_term( ‘Personalize’, ‘product_cat’, $cart_item[‘product_id’])) { $product = $cart_item[‘data’]; // get product data … Read more

How to change a WooCommerce Subscription Deposit and Monthly Payment? [closed]

I THINK I have achieved what I want in this far more simple fee hook, found here https://stackoverflow.com/questions/43415783/change-cart-total-price-in-woocommerce: function prefix_add_discount_line( $cart ) { $discount = $cart->subtotal_ex_tax * 0.1; $cart->add_fee( __( ‘10% Discount’, ‘yourtext-domain’ ) , -$discount ); } add_action( ‘woocommerce_cart_calculate_fees’, ‘prefix_add_discount_line’ ); This is taking 10% off the “To pay now” including tax and totals, … Read more

How to add a new column with text fields to WooCommerce Cart List?

This requires you to override WooCommerce templates: 1) First read: Template structure & Overriding templates via a theme to understand how you can change some templates copying them to your active theme folder 2) Copy the template templates/cart/cart.php located in your Woocommerce plugin to your active theme in woocommerce/cart/cart.php (so not in a “template” subfoder). … Read more

How to remove product attribute row woocommerce using code

I have found a solution after some digging in database: $product_attributes = get_post_meta( $product->id , ‘_product_attributes’ ); $temp_product_attributes = []; foreach($product_attributes as $product_attribute) { foreach($product_attribute as $pt_k => $pt_v) { if ($pt_k !== $attribute_name) { $temp_product_attributes[$pt_k] = $pt_v; } } } update_post_meta( get_the_ID(), ‘_product_attributes’, $temp_product_attributes); First we need to get all of product attributes then … Read more

Woocommerce – auto logout after payment

I used this code in wordpress functions.php, to auto logout customer/user after payment in woocommerce or close the browser function logged_in( $expirein ) { return 6; // 6 in seconds } add_filter( ‘auth_cookie_expiration’, ‘logged_in’ ); function wp_logout2() { wp_destroy_current_session(); wp_clear_auth_cookie(); /** * Fires after a user is logged-out. * * @since 1.5.0 */ do_action( ‘wp_logout2’ … Read more

What Hook/Action is performed when a field in checkout form is changed in WooCommerce

You will need to use ajax to set values in WooCommerce session variables first. Once your values are set in wc()->session, then you can access them anywhere within the WooCommerce hooks or actions. See below code example: /*Ajax Call Back*/ add_action( ‘wp_ajax_my_action’, ‘my_action_callback’ ); $shipping_charges; function my_action_callback() { $shipping_charges = $_POST[‘shipping_charges’]; WC()->session->set(“th_shipping_charges”, $shipping_charges ); } … Read more

Hide products in uncategorized category from search results

Try to add the following lines of code at the end of your theme’s functions.php file: function custom_pre_get_posts_query( $q ) { $tax_query = (array) $q->get( ‘tax_query’ ); $tax_query[] = array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array( ‘uncategorized’ ), ‘operator’ => ‘NOT IN’ ); $q->set( ‘tax_query’, $tax_query ); } add_action( ‘woocommerce_product_query’, ‘custom_pre_get_posts_query’ ); … Read more