Show Discount Percentage on Sale Badge

function g9_add_percentage_to_sale_badge($html, $post, $product) { global $product; $stock = $product->get_stock_status(); $product_type = $product->get_type(); $sale_price = 0; $regular_price = 0; if ($product_type == ‘variable’) { $product_variations = $product->get_available_variations(); foreach ($product_variations as $kay => $value) { if ($value[‘display_price’] < $value['display_regular_price']) { $sale_price…Continue reading

Add Products if Related Products is Empty

function g9_add_categories_related_products($related_posts, $product_id, $args) { if (empty($related_posts)) { $related_posts = get_posts(array( ‘post_type’ => ‘product’, ‘numberposts’ => 3, // Number of products to show ‘post_status’ => ‘publish’, ‘fields’ => ‘ids’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’…Continue reading

Show SKU in Cart

function g9_sku_cart_page($item_name, $cart_item, $cart_item_key) { // The WC_Product object $product = $cart_item[‘data’]; // Get the SKU $sku = $product->get_sku(); // When sku doesn’t exist if (empty($sku)) return $item_name; // Add the sku $item_name .= ‘‘ . __(“SKU: “, “woocommerce”) .…Continue reading