How to change currency programmatically on creating order action?
I have finally found a solution https://hotexamples.com/examples/-/WC_Order/set_currency/php-wc_order-set_currency-method-examples.html $order->set_currency(‘HRK’);
I have finally found a solution https://hotexamples.com/examples/-/WC_Order/set_currency/php-wc_order-set_currency-method-examples.html $order->set_currency(‘HRK’);
I had to add the filter hook for product variation as well. add_filter( ‘woocommerce_product_get_price’, ‘pr_reseller_price’, 10, 2 ); add_filter( ‘woocommerce_product_variation_get_price’, ‘pr_reseller_price’, 10, 2 ); add_filter( ‘woocommerce_product_get_regular_price’, ‘pr_reseller_price’, 10, 2 ); add_filter( ‘woocommerce_product_get_sale_price’, ‘pr_reseller_price’, 10, 2 );
You should ad the custom field to product API response, try this (untested) add_filter( ‘woocommerce_rest_prepare_product’, ‘custom_products_api_data’, 90, 2 ); function custom_products_api_data( $response, $post ) { // retrieve a custom field and add it to API response $response->data[‘purchasing_cost’] = get_post_meta( $post->ID, ‘purchasing_cost’, true ); return $response; }
Is there a proper way to easily bootstrap all the WordPress includes, without having to go all the way through the theme? That’s the wrong question. Shortcodes are far from the only way to run code from a theme or plugin. You’ve correctly identified them as inappropriate for the job though. What I think you … Read more
Okay I found a solution after Slack conversation. It is possible to remove the fields from checkout by unsetting them in woocommerce_billing_fields hook and then re-adding the values again to the order from users profile with woocommerce_checkout_posted_data hook. add_filter( ‘woocommerce_checkout_posted_data’, ‘fill_order_billing_details’ ); function fill_order_billing_details( $data ) { $customer_id = get_current_user_id(); $data[‘billing_first_name’] = get_user_meta( $customer_id, ‘billing_first_name’, … Read more
I also have the same issue when I created a shipping method and what I did is on my function for the ajax call I add something just to have an update on the cart: global $woocommerce; $packages = $woocommerce->cart->get_shipping_packages(); foreach( $packages as $package_key => $package ) { $session_key = ‘shipping_for_package_’.$package_key; $stored_rates = WC()->session->__unset( $session_key … Read more
To answer the question in this posts’s title, you don’t need to check for the page’s URL to see if you’re on the checkout page as Woocommerce has a conditional for that – is_checkout()
Following code solves the purpose: add_filter(‘woocommerce_dropdown_variation_attribute_options_args’,’fun_select_default_option’,10,1); function fun_select_default_option( $args) { if(count($args[‘options’]) > 0) //Check the count of available options in dropdown $args[‘selected’] = $args[‘options’][0]; return $args; }
I think you should jQuery to enable and disable the checkout button. Please try this script. Put this script in the footer.php. jQuery(window).on(‘load’,function(){ setTimeout(function(){ jQuery(‘#payment #place_order’).attr(“disabled”,”disabled”); console.log(‘Hello’); },1000); }); jQuery(document).on(‘change’,’#privacy_policy_field #privacy_policy’,function() { var ischecked= jQuery(this).is(‘:checked’); if(!ischecked){ jQuery(‘#payment #place_order’).attr(“disabled”,”disabled”); console.log(‘unchecked’); }else{ jQuery(‘#payment #place_order’).removeAttr(“disabled”); console.log(‘checked’); } }); Note: This is tested script for your code.
Use $cart_item[‘data’]->get_category_ids() to retrieve the category IDs: $category_ids = $cart_item[‘data’]->get_category_ids(); // array The category_ids you see is not a direct item in the $cart_item array: var_dump( $cart_item[‘category_ids’] ); // null and PHP throws a notice It’s an item in a protected property of the product data ($cart_item[‘data’]) which is an object, or a class instance … Read more