how to allow user select shipping location(a custom locations dropdown) in checkout and recalculate values woocommerce

i need to know 2 things

  1. how do i add custom shipping zones to a determinate contry (I need to add some neightbours of a main city)
  2. How do i allow users to select the shipping zone when chekout or in the cart, and recalculate the total

Confirm order page parameter for woocommerce

I have custom payment button i put on woocommerce checkout page before confirm order page, and it will redirect to confirm order page after the payment have been made.

The url look something like this

mydomainpayment.com/?recipient=someone&amount=' . (string) $  order->get_total() . '&returnurl=myshopdomain.com/(what-parameter-to-put-here-order-id)"><button type="button">Pay With Custom Payment</button></a>'; 

My question is what parameter to put at behind return url there.

Thank You in advance.

How do I make my terms for each product display via foreach loop? (woocommerce)

This is my current loop to display my products via woocommerce. When I do print_r($ category_array); It returns the array, but when I try to use a function to call it so I can do what I want to with the data, it makes and my entire screen doesn’t display after the loop. Maybe it’s a mistake in my function? Still very new to woocommerce and wp_loops. Thank you

            <?php             // WP_Query arguments             $  args = array(                 'p'                      => 'product',                 'post_type'              => array( 'product' ),                 'order'                  => 'ASC',                 'post_per_page' => 20,             );              // The Query             $  query = new WP_Query( $  args );              // The Loop             if ( $  query->have_posts() ) {                 while ( $  query->have_posts() ) {                     $  query->the_post();                     function filter_categories($  categories) {                             foreach ($  categories as $  category) {                                 echo $  category->name;                             }                     }                       ?>                     <div class="row">                         <div class="col-2">                             <?php echo the_post_thumbnail(get_the_ID(), 'thumbnail'); ?>                         </div>                         <div class="col-7">                             <a href="<?= get_permalink(); ?>"><?= the_title()?></a>                             <br/>                             <?php                             $  category_array = get_the_terms(get_the_ID(), 'product_cat');                             filter_categories($  category_array);                             ?>                         </div>                         <div class="col-3 text-right ">Price</div>                     </div>                     <?php                 }             } else {                 // no posts found             }              // Restore original Post Data             wp_reset_postdata();             ?> 

How to modify the WooCommerce shop page to tweak the display price without affecting the actual price under the hood?

The woocommerce shop I am working on imports product price as "£ per g", this is correct for the calculation. On the shop page my client would like the price to be displayed as "£ per 100g" so I need to multiply the price by 100. In functions.php I have the following snippet which lets me change what is displayed (as you can see, I have already edited the text to display correctly), does anyone provide help on how to translate this import price to display price?

add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' );     // Change and return $  price_html variable using the $  price and weight amount     let a = 10     function wb_change_product_html( $  price ) {         $  price_html = '<span class="amount">' . $  price . ' per 100g </span>';   // change weight measurement here              return $  price_html;     }          add_filter( 'woocommerce_cart_item_price', 'wb_change_product_price_cart' );     // Change the cart prices with $  price variable and weight amount     function wb_change_product_price_cart( $  price ) {         $  price = $  price . ' per g'; // change weight measurement here              return $  price;     } 

I’m sure that there’s a quick fix here! I have also added a screenshot of the import columns so that the price change I’m looking for can be seen.

enter image description here

Changing shipping cost in Woocommerce

I am creating a plugin that connects to an 3rd API to request the shipping cost based on the address of the person and the dimensions of the product.

Everything is fine but now I need the values ​​returned by the API to be added to the prices of the shipping methods and I tried with this code but it still doesn’t work.

add_filter('woocommerce_package_rates','test_overwrite_',100,2); function test_overwrite_($  rates,$  package) {  foreach ($  rates as $  rate) {  //Set the price $  rate->cost = $  phpVar1;   <-//variable that receives the value of the shipment }  return $  rates; } 

But I don’t find any way to change the shipping cost with functions..

Is it possible ? Thanks

Change product_type from simple to variable in WooCommerce

I know that WooCommerce plugin store product_type in taxomony I use that code

// TODO change taxonomy // product_type = variable $  terms = get_the_terms($  post_id, "product_type"); foreach ($  terms as $  term) {     $  termId = $  term->term_id;     // TODO figure out why is not work     wp_update_term($  termId, "variable"); } 

Why it not works?

Woocommerce Billing Form not saving User Name or Phone Number?

I have a custom checkout that we’ve built as part of the theme for a site we are building.

When the user presses update to update the shipping or billing address, it wont save the user’s first and last name or their phone number.

I wondered if anyone might be able to help as i am a little stumped here:

<div class="woocommerce-billing-fields">     <?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>          <h3><?php esc_html_e( 'Billing &amp; Shipping', 'woocommerce' ); ?></h3>      <?php else : ?>          <h3><?php esc_html_e( 'Billing Address', 'woocommerce' ); ?></h3>      <?php endif; ?>      <?php do_action( 'woocommerce_before_checkout_billing_form', $  checkout ); ?>      <?php $  customer = WC()->customer;?>         <p class="billing-details <?php if(!is_user_logged_in()) {echo 'hide';}?>">             <?php echo             $  customer->get_billing_first_name() . ' ' . $  customer->get_billing_last_name() . ', ';             if(!empty($  customer->get_billing_company())) { echo $  customer->get_billing_company() . ', ';}             echo $  customer->get_billing_address_1() . ', ';             if(!empty($  customer->get_billing_address_2())) { echo $  customer->get_billing_address_2() . ', ';}             echo $  customer->get_billing_city() . ', ' .             $  customer->get_billing_state() . ', ' .             $  customer->get_billing_postcode()             ;?>         </p>         <p class="change-billing-details <?php if(!is_user_logged_in()) {echo 'hide';}?>">Change</p>       <div class="woocommerce-billing-fields__field-wrapper <?php if(!is_user_logged_in()) {echo 'show';}?>">         <?php         $  fields = $  checkout->get_checkout_fields( 'billing' );          foreach ( $  fields as $  key => $  field ) {             woocommerce_form_field( $  key, $  field, $  checkout->get_value( $  key ) );          }         ?>         <p class="update-billing-details updating">Update Billing Details</p>     </div>      <?php do_action( 'woocommerce_after_checkout_billing_form', $  checkout ); ?> </div>  <?php if ( ! is_user_logged_in() && $  checkout->is_registration_enabled() ) : ?>     <div class="woocommerce-account-fields">         <?php if ( ! $  checkout->is_registration_required() ) : ?>              <p class="form-row form-row-wide create-account">                 <label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">                     <input class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" id="createaccount" <?php checked( ( true === $  checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true ); ?> type="checkbox" name="createaccount" value="1" /> <span><?php esc_html_e( 'Create an account?', 'woocommerce' ); ?></span>                 </label>             </p>          <?php endif; ?>          <?php do_action( 'woocommerce_before_checkout_registration_form', $  checkout ); ?>          <?php if ( $  checkout->get_checkout_fields( 'account' ) ) : ?>              <div class="create-account">                 <?php foreach ( $  checkout->get_checkout_fields( 'account' ) as $  key => $  field ) : ?>                     <?php woocommerce_form_field( $  key, $  field, $  checkout->get_value( $  key ) ); ?>                 <?php endforeach; ?>                 <div class="clear"></div>             </div>          <?php endif; ?>          <?php do_action( 'woocommerce_after_checkout_registration_form', $  checkout ); ?>     </div> <?php endif; ?> 

Woocommerce product query not working in other WPML languages

I am trying to hide all Woocommerce products from a specific product category on the main shop archive page (products only visible when a customer goes to the specific category archive).

The following code is working to hide those products in my original language (Dutch), but not in the other 3 site languages, even though I also added their correct category id’s.

add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' ); function prefix_custom_pre_get_posts_query( $  q ) {      if( is_shop() || is_page('shop') ) { // set conditions here       $  tax_query = (array) $  q->get( 'tax_query' );          $  tax_query[] = array(              'taxonomy' => 'product_cat',              'field'    => 'term_id',              'terms'    => array(27,952,951,1119), // set product categories here              'operator' => 'NOT IN',       );          $  q->set( 'tax_query', $  tax_query );   } } 

Anyone knows how I could adapt this code snippet so it works in all languages? Thanks!