Aramex plugin errors - wordpress

I use this plugin: https://wordpress.org/plugins/aramex-shipping-woocommerce/
But I try any means but I failed to solve the issue . I have active Aramex account with all details, I setup plugin in woocommerce settings, but after click view cart show Aramex: ERR52 - Destination my city and address are invalid while I start shop as a guest. Also is it possible to disable ZIP code while use Aramex? Please any one with idea what cause this

the zipcode requirements are based on each country , for eg: GCC countries do not need zip code and most other countries need zipcode.

You can have WooCommerce override the default setting that makes the field required by adding a filter to your theme's functions.php. It would be best practice is to create a child theme so it won't get overwritten each time you update the theme.
For example, this code will remove the "required" state from the billing and shipping postal codes during checkout (if the shipping country is not 'US'):
add_filter( 'woocommerce_checkout_fields','custom_override_default_address_fields' );
function custom_override_default_address_fields($fields){
global $woocommerce;
$country = $woocommerce->customer->get_shipping_country();
if($country !== 'US'){
$fields['billing']['billing_postcode']['required'] = false;
$fields['shipping']['shipping_postcode']['required'] = false;
}
return $fields;
}
For more details on filters and fields available to edit via filtering see WooCommerce Customizing checkout fields using actions and filters doc

Related

WooCommerce shows admin details

I've got a problem
Once I go to the checkout page after having added one item or more to my cart, it shows the billing checkout form with already filled inputs. See below:
It shows my full details, including email and phone number to every possible buyer.
I installed the SendGrid plugin and discovered it, but removing the plugin did not fix the issue.
I cannot see in any WordPress option where I can edit the value of these input boxes to be empty.
Super weird...
one thing you can try, is using a hook to alter the current "default" value of your form
Since I don't know, in what priority the default value is already getting changed, I would start by setting it to 20, and then trying 30, 40 etc.
// Hook in -
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields', 20 );
// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
$address_fields['first_name']['placeholder'] = 'Firstname';
return $address_fields;
}
Hope this works - It was way to long for a comment.

Manipulate woocommerce product edit page

I am new to wordpress and woocommerce development and I am just wondering, how to manipulate an admin-screen in a clean, updateable way.
For example, I want to add a custom field to a product edit page (see screen):
I know, that I have to write a custom extension, but is it possible, to manipulate admin-screens of other extensions? I couldn't find any suitable tutorial? Maybe someone has a hint, where to start?
The feature of creating custom fields for products is baked right into WooCommerce, whether to implement it directly in functions.php or do the same via a plugin is left to one's sole discretion.
Remi Corson has written an excellent article detailing the same.
Here's the gist :
1.Create the fields using the woocommerce_product_options_general_product_data hook
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
// Define your fields here.
// You can create text, textarea, select, checkbox and custom fields
}
2.When product is saved save the value entered in your custom field using woocommerce_process_product_meta hook
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields_save( $_post_id ) {
//save field values
}
WooCommerce is a WordPress plugin that will help you to turn your website into an eCommerce store.
Yes, you can write an Extension ( or ADD-On) for this plugin, in fact there are already hundreds of Extension ( free and Paid ) have been made for it.
In order to create an Extension ( or ADD-ON ) for this plugin, you need to understand 2 things:
WooCommerce API
http://docs.woothemes.com/document/create-a-plugin/
WordPress API https://codex.wordpress.org/Writing_a_Plugin

How to properly initialize Woocommerce Cart

I have a custom template file, rendering some products and their Add To Cart buttons, that I am trying to implement manually. When Add to Cart is pressed, the page is reloaded and a $_POST variable containing some data adds the new products. 'cart_contents_count' also reflects the added item. However, when I go to the cart page, it's empty. Please see the following code.
global $woocommerce;
if ( isset( $_POST['AddedToCart'] ) ) {
$woocommerce->cart->add_to_cart($_POST['event'], $_POST['qty']);
}
$cart_total = $woocommerce->cart->cart_contents_count;
When I however go to the normal default shop page ( /shop/ ) and add a product from there, my cart page indicates that this product has been added. When I NOW go to my custom page and add products from that Add To Cart button, it works perfectly.
It seems to me that, before I run the above-mentioned code, I must check if a Cart Session has been initialized, and if not, initialize it. Could someone please confirm for me that I understand it right and show me how to initialize the cart?
Here is a solution if your custom form is on a page template. This code goes in your functions.php file. Be sure to change yourtheme_template to something more unique. Also, change the items in the $session_templates array to the template filenames where you want this filter to be used. It uses the template_include filter, which isn't an easy filter to track down, let alone $woocommerce->session->set_customer_session_cookie(true) - Special thanks to #vrazer (on twitter) for the help.
function yourtheme_template($template) {
//List of template file names that require WooCommerce session creation
$session_templates = array(
'page-template-file-name.php', 'another-page-template-filename.php'
);
//Split up the template path into parts so the template file name can be retrieved
$parts = explode('/', $template);
//Check the template file name against the session_templates list and instantiate the session if the
//template is in the list and the user is not already logged in. If the session already exists from
//having created a cart, WooCommerce will not destroy the active session
if (in_array($parts[count($parts) - 1], $session_templates) && !is_user_logged_in()) {
global $woocommerce;
$woocommerce->session->set_customer_session_cookie(true);
}
return $template;
}
//Filter to run the WooCommerce conditional session instantiation code
add_filter('template_include', 'yourtheme_template');
I resolved this problem by making sure the $woocommerce->cart->add_to_cart() line is positioned before any headers are sent. I.E, before get_header() is called on my custom template.
In the WooCommerce version 2.5 they change the way the sessions works. https://woocommerce.wordpress.com/2015/10/07/new-session-handler-in-2-5/
What i did was install this plugin https://github.com/kloon/woocommerce-large-sessions then my cart is not empty any more with guess users.
I hope it helps someone else.

Wordpress woocommerce, adding 2 items to cart at same time

is it possible to add 2 items to a cart at the same time? like a free product that is associated with a specifically selected product?
I currently add to the cart this way
$.get('/?post_type=product&add-to-cart=' + productId, function() {
// stuff here..
});
If its not possible do you know what hooks i might need to hook into to change it?
Thanks in advance..
There may be some theme resources that load some data with same URL including the query string, which is making WP INIT function to add product another time.
My solution is to add following code in the header.php of theme before any HTML prints out:
if(isset($_GET['add-to-cart'])){
//checkout can be replaced with any slug
header('Location: '.site_url().'/checkout/');
exit;
}

WooCommerce Show Payment Gateways for Logged In Customers Only

I am setting up an ecommerce site using Wordpress and WooCommerce. We are using the wordpress member accounts to track customer information, and we need a way for logged in members only to be able to choose to purchase their cart "on credit", meaning no payment is required to place the order. Basically what I have done is hi-jacked the "Check" option (since we don't need it anywhere else) and renamed it "Credit" since it allows for the functionality we need.
However, I need a way for the "Credit" (check) option to only display if the user is logged in. Is there any way I can just "unhook" this option if the user isn't logged in? This seems like something that would be easy to do, but I couldn't find anything about it. Any help is appreciated.
The original answer to this question (from BWDesign) no longer works due to changes in WooCommerce (at least from WooCommerce 2.1.7 onwards, possibly before). This does the trick now (tested on 2.1.7 and 2.1.8), add it to e.g. your functions.php file:
add_filter( "woocommerce_available_payment_gateways", "rp_filter_gateways", 9999 );
function rp_filter_gateways($args) {
if(!is_user_logged_in() && isset($args['cheque'])) {
unset($args['cheque']);
}
return $args;
}
I just found the solution. In the class-wc-cheque.php file, the check or "cheque" (crazy brits) option is hooked using add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );. So the solution was simply to add this code to my functions.php file:
if(!is_user_logged_in()){
remove_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );
}
Hope this helps!

Resources