Setting WooCommerce SKU programmatically [closed]

You should use save_post hook. Try the code below: function wpse_304031_save_post( $post_id, $post ) { // return if autosave if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) { return; } $your_sku = ‘Custom SKU for ‘ . $post->post_title; if( $post->post_type == ‘product’ ) { if( empty( get_post_meta( $post_id, ‘_sku’, true ) ) ) { update_post_meta( … Read more

Woocommerce changing add to cart button text as icon [closed]

Default “Add to Cart” template of WooCommerce at “templates/loop/add-to-cart.php” uses function “esc_html()” which escapes HTML blocks in return value. The code you have added is correct. You just need to remove “esc_html()” function from “templates/loop/add-to-cart.php“. // Default Template Code echo apply_filters( ‘woocommerce_loop_add_to_cart_link’, sprintf( ‘<a rel=”nofollow” href=”https://wordpress.stackexchange.com/questions/304517/%s” data-quantity=”https://wordpress.stackexchange.com/questions/304517/%s” data-product_id=”https://wordpress.stackexchange.com/questions/304517/%s” data-product_sku=”https://wordpress.stackexchange.com/questions/304517/%s” class=”https://wordpress.stackexchange.com/questions/304517/%s”>%s</a>’, esc_url( $product->add_to_cart_url() ), esc_attr( isset( … Read more

Woocommerce change price in cart when discounted

You can use this filter in your theme or plugin to filter the product prices: function filter_woocommerce_price( $price, $product ) { // 1. Set your $price_percent variable // 2. Subtract the price_percent from the price $price – $price_percent // 3. Set the new $price return $price; } add_filter( ‘woocommerce_product_get_regular_price’, ‘filter_woocommerce_price’, 10, 2 ); By the … Read more

WooCommerce – Split Multiple Items into Individual Line Items

So I ended up combining a few answer out there and split out orders when adding to the cart, and also when updating the cart. The below works, though it’s purely a front end customization. Hope this helps someone else! function bbloomer_split_product_individual_cart_items( $cart_item_data, $product_id ){ $unique_cart_item_key = uniqid(); $cart_item_data[‘unique_key’] = $unique_cart_item_key; return $cart_item_data; } add_filter( … Read more

is_shop doesn’t work for woocommerce [closed]

is_shop() is returning false because the WordPress query isn’t set up yet when functions.php is run. If you attach it to a hook, like wp_loaded, it should work. add_action( ‘wp_loaded’, ‘remove_main_content’ ); function remove_main_content() { if( is_shop() ) { remove_action(‘woocommerce_before_main_content’, ‘woocommerce_breadcrumb’, 20 ); } }

Generating a perfect loop

That’s because you’re looping twice due to the while. Completely unecessary. foreach ($orders_ids as $details) { $order = wc_get_order($details->order_id); $fornavn = $order->get_billing_first_name(); $etternavn = $order->get_billing_last_name(); $deltakerkategori = $order->get_meta( ‘_billing_field_447’, true ); $deltakerradio = $order->get_meta( ‘_billing_field_538′, true ); echo ”.$fornavn.’ ‘.$etternavn.’ ‘.$deltakerkategori.”https://wordpress.stackexchange.com/”.$deltakerradio.'<br>’; } Additionally, if that doesn’t fix it due to…well, magic, try this patch: foreach( … Read more

Error with get_price (and others) in self-written plugin to show price

The error Is coming from the file: /wp-content/plugins/woocommerce-display-various/display_various.php Line 180. Disable the plugin ‘woocommerce-display-various’ and check if the problem still exists. Your code Why are you using output buffering (ob_start())? Furthermore you’re not using it correctly. There’s alot to improve on your code… See my changes: add_action(‘init’,’add_custom_price_shortcodes’); function add_custom_price_shortcodes() { if ( class_exists( ‘woocommerce’ ) … Read more

Copy order items with metadata between orders – Woocommerce

Just change the $item_id to $to_order_item_id and you don’t even have to touch the order_item_meta since it is still associated with the proper $item_id. So your foreach from above would be … foreach($order->get_items() as $item_id=>$item) { wc_update_order_item($item_id, array(‘order_id’=>$to_order_item_id)); } Then you could even calculate the new totals of both orders after by using … $original_order … Read more