Is it possible to recalculate cart prices? [closed]

Maybe you need to add : wc_delete_product_transients($post->ID); I did something like this in opther project and thats worked: if (is_user_logged_in()) { add_filter(‘woocommerce_product_variation_get_regular_price’, ‘my_custom_price’, 10, 2); add_filter(‘woocommerce_product_variation_get_price’,’my_custom_price’, 10, 2); } function my_custom_price( $price ) { global $post; // Delete product cached price (if needed) wc_delete_product_transients($post->ID); // Return the new price return $price = ($price * 1.1) … Read more

why featured product not updated in postmeta table in woocommerce?

Since 3.0 featured products are marked as featured by being given the featured term that WooCommerce creates in the product_visibility taxonomy. But to tell if a product is featured, instead of checking the terms directly or using get_post_meta() (which wouldn’t work anymore anyway), use the get_featured() method of WC_Product: $product_id = 1; $product = wc_get_product( … Read more

How can i create a WooCommerce product programatically or using sql query?

This will give you a base to start: function generate_simple_product() { $name=”My Product Name”; $will_manage_stock = true; $is_virtual = false; $price = 1000.00; $is_on_sale = true; $sale_price = 999.00; $product = new \WC_Product(); $image_id = 0; // Attachment ID $gallery = self::maybe_get_gallery_image_ids(); $product->set_props( array( ‘name’ => $name, ‘featured’ => false, ‘catalog_visibility’ => ‘visible’, ‘description’ => … Read more

Separate Categories from WC Product loop when display type is set to both on the category

I have found the solution I was looking for. Using the following code will stop displaying categories in the product loop. remove_filter( ‘woocommerce_product_loop_start’, ‘woocommerce_maybe_show_product_subcategories’ ); Then use the following function in a separate section of the page will render the categories in a separate section. woocommerce_maybe_show_product_subcategories()

global $post; in WooCommerce

You should avoid using global variables where possible. For metaboxes you should use the $post variable that is passed to the callback function instead: add_meta_box( ‘supplier_package_box’, __( ‘Supplier’, ‘supplier’ ), ‘populate_meta_box’ ); function populate_meta_box( $post ){ print_r($post); }

Accessing parameters when adding filter

When you call add_filter(), set the fourth parameter to 3 (which is the number of parameters accepted by the callback function which in your case is change_rating_output()), and then change your change_rating_output() function so that it accepts the $rating and $count parameters: add_filter(‘woocommerce_product_get_rating_html’, ‘change_rating_output’, 10, 3); function change_rating_output($html, $rating, $count){ // Now do what you … Read more