Setting a default variation for each product on the child theme functions.php file

I'm trying to set a default variation for each product so I wouldn't need to set it manually on each product separately through the admin panel. I tried to insert the code below but it doesn't work. I'm using Variation Swatcher for WooCommerce plugin as well but from analyzing the DB it shouldn't cause the issue. My code: function setting_product_default_attributes() { global $product; if (!count($default_attributes = get_post_meta($product->get_id(), '_default_attributes'))) { $new_defaults = array(); $product_attributes = $product->get_attributes(); if (count($product_attributes)) { foreach ($product_attributes …
Category: Web

Wordpress WooCommerce programmatically set EU VAT when creating an order in PHP

I am really struggling and I really hope that you can help me with this questions. So the question I am struggling with is: How can I add the EU VAT with a checkmark in the order? Currently I only get a big red cross in the EU VAT column in the wordpress dashboard. What am I missing? Screenshot of the order with a big red cross (Check the fifth column) https://imgur.com/a/Oox4k5k The code I made an endpoint in PHP …
Category: Web

Overriding woocommerce payment with a token-based payment method

The project I am working is to create a platform,where every items posted can be exchanged for 1 token, instead of paying prices. To do this, I`ve tried YITH /SUMO /Woocommerce reward points plugins, and Dokan as the multi-vendor plugin. Here are the problems I encountered: Among all the reward points plugins, SUMO reward point is closest to my needs, as it provide payment gateway using award points. However,in each reward points plugins I tried,points-payment is just a converted version …
Category: Web

Prevent reload page after add to cart submission

I'm working on custom woocommerce theme, using my own code. I need to add products to the cart without page refresh. I'm using the code below, It's working correctly but when I add product the shop page reload. Could someone help me how can I develop this. <?php $product = get_product(get_the_ID());?> <a href="<?= $product->add_to_cart_url(); ?>" title="Add to cart" class="addToCart"></a>
Category: Web

Looping through and combining calls to Woocommerce REST API

I have to make calls to multiple pages of a Woocommerce product database (getting all products in one go seems to not be an option), and the looping and collection of the results isn't working as I expect. I should see an array with just under 900 objects, but all I'm seeing is an empty array. I'm very new to PHP. THe relevant code below: function get_awesome_products() { for ($count = 1; $count <= 9; $count++ ) { if ($count …
Category: Web

Gutenberg for WooCommece Product Page in WordPress 6.0+

I wanted to enable Gutenberg for My Single Product Description so I followed this guide https://dev.to/kalimahapps/enable-gutenberg-edit function activate_gutenberg_product( $can_edit, $post_type ) { if ( $post_type == 'product' ) { $can_edit = true; } return $can_edit; } add_filter( 'use_block_editor_for_post_type', 'activate_gutenberg_product', 10, 2 ); function enable_taxonomy_rest( $args ) { $args['show_in_rest'] = true; return $args; } add_filter( 'woocommerce_taxonomy_args_product_cat', 'enable_taxonomy_rest' ); add_filter( 'woocommerce_taxonomy_args_product_tag', 'enable_taxonomy_rest' ); function register_catalog_meta_boxes() { global $current_screen; // Make sure gutenberg is loaded before adding the metabox if ( method_exists( $current_screen, …
Category: Web

Online wc-blocks-style.css rendering instead of the hosted wc-blocks-style.css

On my archive page is a sidebar which has a style I want to edit. On my local machine, the style is in wc-blocks-style.css. I edited it successfully and it renders fine. However, after deployment of the website to CPanel, the style is being rendered from an online wc-blocks-style.css. The style link is as follows: <link rel='stylesheet' id='wc-blocks-style-css' href='https://c0.wp.com/p/woocommerce/6.5.1/packages/woocommerce-blocks/build/wc-blocks-style.css' media='all' />. All other Woocommerce styles are also loaded from this online repository. My question is, how do I make my …
Category: Web

from website from scratch to wordpress

I am not a full time website developer although i've developed some websites from scratch with HTML, CSS, Bootstrap, Javascript/jQuery etc usually for websites that have very specific purposes (e.g. custom calculators for business to find profit, margins, etc). For very simple websites I've used Wix. Now I'll start working on more complex but usual projects like e-shops, hotel pages etc. and I'm thinking to move to wordpress and woocommerce for e-shop pages, as it has many stuff that i'll …
Category: Web

Get tax rate label of "orderlineitem" in woocommerce and store in xml

How to show tax percentage for each item in order in an xml. i create xml when order is paid. but need to show item tax labels for each items for example. "7% Mswt", "19% Mswt". function get_line_items( $order ) { $items = []; /** @var \WC_Order_Item_Product $line_items */ $line_items = $order->get_items( 'line_item' ); // loop through each item in order foreach ( $line_items as $item_id => $item ) { // get the product /** @var \WC_Product $product */ $product …
Category: Web

Add sku to product url in WooCommerce

I want to add product SKU to my products url in WooCommerce like this example : example.com/product/sku/productname I checked this topic, but in this method sku will add to end of product name not used as I want : product/sku/productname
Category: Web

Get product categories and add them to a custom taxonomy

I'm working on a WooCommerce webshop. I have divided all my products into categories. Example: Clothing: -Tshirts -Jeans -Etc. Likewise, all brands are also divided into categories. Example: Brands -Brand1 -Brand2 -Etc. I want to copy or mirror the category and sub-categories of "Brands" to a custom taxonomy. So when I have a product in the "Brand 1" category, then this product must be automatically entered into a custom taxonoy with the same name: "Brand 1" The products in woocommerce …
Category: Web

Visual composer custom element error

I am creating a custom element where I need to load woo-commerce product categories as dropdown (in visual composer element edit option) but I am getting this error. can someone tell me where is the problem? here is the code: <?php add_shortcode('woo_my_cat_sub_cat_show_element_code','woo_my_cat_sub_cat_show_element_functions'); function woo_my_cat_sub_cat_show_element_functions($atts,$content){ extract(shortcode_atts(array( 'woo_my_cat_list' => '', ),$atts)); ob_start();?> <!-- I will do the frontend here --> <?php return ob_get_clean(); } if(function_exists('vc_map')){ /*** * dynamic fields for the element */ $args = array( 'taxonomy' => 'product_cat', // 'number' => …
Category: Web

Custom WooCommerce rewrite rules with comma delimiter

I'm trying to troubleshoot a wide-scale problem. I'd like to rewrite default WooCommerce permalinks for categories, to delimiter as commas. Let's take an example: Brand Model Generation Engine Product The permalink structure I'd like to have: /chip-tuning-Ford /chip-tuning-Ford-Focus /chip-tuning-Ford-MK3-FL /chip-tuning-Ford-MK3-FL-1.5TDCi-75kW /chip-tuning-Ford-MK3-FL-1.5TDCi-75kW-Basic-Box I did this via generate_rewrite_rules action, but currently, we have about 4000 categories and 9000 products, so each combination takes a lot of time and space. All rewrite rules by WP default are saved into one field on the …
Category: Web

Next/Previous Product with custom order by price & products inside the product category

How to create next/prev buttons that are price sorted and give results inside the product category you are in? This question has been asked multiple times and despite the multiple threads there wasn't an exact answer. Only relatively close ones that didn't do all of the above. Below you will find my answer which works in my tests so far.
Category: Web

Automated Cart Update With Alert Box Each Time

New To PHP and, I am currently attempting to create a plug in that creates an alert box every time the quantity in a cart is changed. So far I have successfully implemented updating the cart automatically, but I am having trouble determining how to create an alert box on update each time that references the new cart total. Any advice would be appreciated. TLDR: Creating a plug in that will display an alert box when you change the quantity …
Category: Web

How to add refund in custom payment gateway woocommerce

I want to add refund to the woocommerce-payment-gateway in class WC_Custom_Gateway extends WC_Payment_Gateway function __construct() { $this->supports = array('products', 'refunds'); $this->id = 'custom'; $this->icon = plugins_url('../assets/custom-logo.png', __FILE__); $this->has_fields = true; $this->method_title = 'Custom'; $this->method_description = 'Payment using Custom card'; $this->init_form_fields(); $this->init_settings(); $this->title = sanitize_textarea_field($this->get_option('title')); $this->description = sanitize_textarea_field($this->get_option('description')); $this->enabled = sanitize_key($this->get_option('enabled')); $this->discount = intval($this->get_option('discount')); $this->token = sanitize_text_field($this->get_option('token')); $this->client = sanitize_text_field($this->get_option('client')); $this->back_url = esc_url_raw($this->get_option('back_url')); $this->response_type = $this->get_option('response_type'); add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); // if (is_admin()) { // add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); …
Category: Web

Woocommerce modifying the html on the checkout page?

I'm trying to wrap 'some' of the fields of the checkout page in a div and inject some buttons because I am implementing some address validation. Basically to start with I need a wrapper around company, address line 1, address line 2, town and postcode so I can show/hide them but I can't seem to get anything to work. Here's what I've tried - In my filters file: function change_woocommerce_field_markup($field, $key, $args, $value){ if($key === 'billing_company') { $field = '<div …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.