Save and display selected product option and cost as cart item data in WooCommerce

The following revisited code will change cart item subtotal to the calculated sum of product + color option and will reflect this change to cart totals. It will save the option as order item meta data, when order is placed. The code: // Display Select field before add to cart button add_action( ‘woocommerce_before_add_to_cart_button’, ‘colors_options_before_add_to_cart_button’ ); … Read more

Woocommerce Product Price Inserted programmatically doesn’t get displayed In Single Product Page

Try the following using the WC_Product Object and methods instead: // Starting scrape $html = file_get_html(‘http://sitenam.com/page-1/’); $price = (float) $html->find(‘span[class=”price”]’, 0)->innertext; // Saving the new product $post_id = wp_insert_post( array( ‘post_author’ => 1, ‘post_content’ => ‘Content Here’, ‘post_status’ => “publish”, ‘post_title’ => “Product Title Here”, ‘post_parent’ => “product-title-here”, ‘post_type’ => “product”, ) ); // Setting … Read more

Woocommerce SKU on ALL products page [closed]

Hope this code will helpful for you, the sku will be displayed at the end of shop loop function shop_display_skus() { global $product; if ( $product->get_sku() ) { echo ‘<div class=”product-meta”>SKU: ‘ . $product->get_sku() . ‘</div>’; } } add_action( ‘woocommerce_after_shop_loop_item’, ‘shop_display_skus’, 9 );

woocommerce change order statuses count for specific role

Normally pre_get_post doesn’t change wordpress views post count. You have to call another filter hook to change to count. add_action(‘pre_get_posts’, function ($query) { global $pagenow; if (isset($query->query_vars[‘post_type’])) { if ($query->query_vars[‘post_type’] == ‘shop_order’ && (‘edit.php’ == $pagenow)) { if (!$query->is_main_query()) { return; } // I manipulate $query here // Get Post Count Here For Each Status … Read more

Create WooCommerce new order with specific ID

Well.. You can add meta for original and cloned order. Just add +1 for it, each time when you will clone items. function create_order( $original_order_id, … try { $new_order = new WC_Order(); $new_order->set_props( array( … } $original_order = wc_get_order( $original_order_id ); $order_item_num = $original_order->get_meta(‘_order_items_num’); if($order_item_num >= 1) { $new_order->update_meta_data( ‘_order_item_num’, $order_item_num+1 ); $new_order->save(); $original_order->update_meta_data( ‘_order_items_num’, … Read more

Woocommerce Product Image and Thumbnails custom function

In short: We are going to overwrite the default template and change the function that is being called to generate our tag and the image inside it. Next, we are going to create this function into our functions.php and add the attribute we want to the tag. copy/paste the template woocommerce/templates/single-product/product-image.php to your directory: your-child-theme/woocommerce/single-product/product-image.php … Read more