Woocommerce quick checkout form [closed]

I got it by using wc_create_order here is the full code `if ( isset( $_POST[‘submitted’] ) ) { $address = array( ‘first_name’ => $_POST[‘fullname’], ’email’ => $_POST[’email’], ‘phone’ => $_POST[‘phone’], ‘address_1’ => $_POST[‘address’], ‘city’ => $_POST[‘city’], ); $order = wc_create_order(); $order->add_product( get_product( get_the_id() ), $_POST[‘quantity’] ); $order->set_address( $address, ‘billing’ ); $order->set_address( $address, ‘shipping’ ); $order->set_payment_method( … Read more

How-To: Get meta data from the users last order in woocommerce

First thing is to grab the last order ID, you can do it with a simple WP_Query $args = array(‘post_type’=>’product’, ‘posts_per_page’=>1, ‘orderby’=>’ID’, ‘orderby’=>’DESC’); $query= WP_Query($args); As this will only give only one result, you don’t need to loop the result, $order_id= $query->posts[0]->ID; Now, you can reach the order data, $order = WC_Order($order_id); You can use … Read more

add custom menu in woocommerce dashboard [closed]

You can use the following to create a sub menu under woocommerce. Please use the following for reference. https://developer.wordpress.org/reference/functions/add_submenu_page/ add_action(‘admin_menu’, ‘testing_submenu_page’); function testing_submenu_page() { add_submenu_page( ‘woocommerce’, ‘sub menu’, ‘sub menu’, ‘manage_options’, ‘woo-subpage-test’, ‘test_callback’ ); } function test_callback() { echo ‘<div class=”wrap”><div id=”icon-tools” class=”icon32″></div>’; echo ‘<h2> Sub menu test page</h2>’; echo ‘</div>’; } Example what the … Read more

WooCommerce doesn’t show UK countries in the shipping options [closed]

You won’t be able to find England specifically in their list. The UK treats several areas as separate countries, and other regions can only be separated by postal code. United Kingdom Republic of Ireland Jersey Guernsey Isle of Man https://github.com/woocommerce/woocommerce/blob/master/i18n/countries.php I should also mention that the “Sell to countries…” field controls the Billing side of … Read more

Hiding all products except for one in wordpress admin panel

You have to use pre_get_posts hook to alter the WordPress main query. $query->get() : https://developer.wordpress.org/reference/classes/wp_query/get/ is_admin() : https://codex.wordpress.org/Function_Reference/is_admin pre_get_posts hook : https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts // Handle the main query and set the post ID to 9 function wpse_288586_hide_products($query) { // We have to check if we are in admin and check if current query is the main … Read more

Customizing the add to cart function

To do this you need to use the woocommerce ‘woocommerce_add_to_cart’ hook to add your custom function. something like this : add_action(‘woocommerce_add_to_cart’, ‘my_function’); function my_function(){ //…….. } This has been answered in another question here : https://stackoverflow.com/a/34255005/3134410

Add A Button to WooCommerce Product Page

Please use the following code snippet. It’ll add a new button right after the add to cart button. The code is well commented, hope that’ll be helpful for you. add_action( ‘woocommerce_after_add_to_cart_button’, function() { /** * If you need product data here you can set $product as global * then you can easily access product data … Read more

Move related products after product summary? [closed]

Related Product Section is already in the woocommerce_after_single_product_summary hook. Now You need to change the priority. Related Products Priority is given: 20 If You want to show it before product tab section, then you have to make the priority less than 10. such as 9 /** * Hook: woocommerce_after_single_product_summary. * * @hooked woocommerce_output_product_data_tabs – 10 … Read more

Send form data to functions.php

The answer is AJAX. Each time the totals are calculated, send the form data to the wp ajax handler. Step 1: pass your ajax URL from PHP to javascript using wp_localize_script just after you enqueue your script file. wp_enqueue_script(‘myScript’, ‘my/script/path.js’); wp_localize_script(‘myScript’, ‘php_params’, [‘ajaxurl’=>admin_url(‘admin-ajax.php’)]); Step 2: make the AJAX call in your script. $.ajax({ type: “POST”, … Read more