How do i add whatsapp api link to email orders using the customer phone number? - api

I would like to add whatsapp link to admin complete orders email, that takes the customer phone number, and adds it to the whatsapp api link.
The idea is that, when i receive notification about order, i can contact my customer using whatsapp and let him know i got his order.
so it should look like this:
api.whatsapp.com/send?phone= {{customer phone number}} &text=...

Add the follows code snippet in your active theme's functions.php and changes the text messages as per you.
function add_wp_link_woocommerce_completed_order_email( $order, $sent_to_admin, $plain_text, $email ) {
if ( $email->id == 'customer_completed_order' || $email->id == 'new_order' ) {
$link = 'https://wa.me/'.$order->get_billing_phone( 'edit' ).'/?text='.urlencode( 'your text messages' );
echo '<div style="margin-bottom: 40px;">
<h2>'.__( 'Customer WhatsApp link', 'text-domain' ) .'</h2>
<p>'.__( 'Contact', 'text-domain' ).'</p>
</div>';
}
}
add_action( 'woocommerce_email_customer_details', 'add_wp_link_woocommerce_completed_order_email', 99, 4 );

Related

How to Format Sending Text in Whatsapp React Native

What I wanted is to send data that is written in object form in proper formate like stores have receipt my code is
var date = new Date().getDate();
const UploadDataCredentials = {
user_id: user_id,
user_detail: [Name, Phone, Address],
order_detail: Data,
total_price: TotalPrice,
order_time: date,
status: 'Pending',
};
Linking.openURL(`whatsapp://send?text=${JSON.stringify(UploadDataCredentials)}&phone=+923354584582`)
props.navigation.replace(navigationstring.BOTTOMTABHOME);
so final i know answer of my question code is below
onPress={() => {
Linking.openURL(`whatsapp://send?text=${` Hey Dear in am intrusted in that Book \n\n\n Name : ${item.name} \n\n Book Info : ${!!item.info ? item.info : item.desc} \n\n Price : ${price}`}&phone=+923354584582`)
}}>
here /n represent Next line
you can formate whatsapp output message with any formate you want in text

Yii2 redirect to previous page after update review

I have a page comp/computer?id=15
it has reviews that can be edited through link
http://comp/computer/update?id=3 = with FORM and submit button
how to go back after sumbit
public function actionUpdate($id)
{
$model = new ReviewForm();
$comment = Review::findOne($id);
if ($model->load($this->request->post())) {
$comment->text = $model->text;
if ($comment->save(false)) {
return $this->redirect(["?id=15"], ); ????????????
}
Yii::$app->session->setFlash(
'success',
'Success'
);
}
$model->setAttributes($comment->getAttributes(['name', 'email', 'text']));
return $this->render('update', compact('model'));
}
simply use referrer.
return $this->redirect(Yii::$app->request->referrer)
If it has no referrer or link open directly then you should either pass computer_id as param or you must have computer_id as foreign key in your review table.
Let say you have relationship with review and computer table. then you can use like this.
$compId = $comment->computer_id; // or 15 or you can paas param here
return $this->redirect(["comp/computer", "id"=> $compId]);
if comp is your hostname then
return $this->redirect(["computer", "id"=> $compId]);
its should be controller/action
return $this->redirect(["controllerId/actionId", "id"=> $compId]);
Send via mobile, sorry for typos.

There are no available services for the countries you’ve selected" with CarrierService

I am integrating carrier service API for shopify store. I have partner account and also i have created development store. After installed my app in my store and subscribed carrier service. But in store shipping settings page i got an error
There are no available services for the countries you’ve selected
How to overcome this issue?
I have in the settings page:
My Carrier Service 5588680759
Rate adjustment: 0% + $0.00
There are no available services for the countries you’ve selected.
Automatically offering future shipping services when they become available
Screenshot:
how can i implement on Checkout Page?
I had the same problem and i solved it changing the callback url of the carrier service to public on my shopify application, you have to check if the url is accessible for everyone. (sorry for my english)
Shopify Documentation
You have to define Call url in shipment carries
"callback_url"=> base_url().'shipment/rates'
add these in controller or file which you add in call url
$filename = time();
$input = file_get_contents('php://input');
file_put_contents($filename.'-input', $input);
// parse the request
$rates = json_decode($input, true);
// log the array format for easier interpreting
file_put_contents($filename.'-debug', print_r($rates, true));
// total up the cart quantities for simple rate calculations
$quantity = 0;
foreach($rates['rate']['items'] as $item) {
$quantity =+ $item['quantity'];
}
// use number_format because shopify api expects the price to be "25.00" instead of just "25"
// overnight shipping is 5 per item
$overnight_cost = number_format(5, 2, '', '');
// overnight shipping is 1 to 2 days after today
$on_min_date = date('Y-m-d H:i:s O', strtotime('+1 day'));
$on_max_date = date('Y-m-d H:i:s O', strtotime('+2 days'));
// build the array of line items using the prior values
$output = array('rates' => array(
array(
'service_name' => 'Shipment Local',
'service_code' => 'SL',
'total_price' => $overnight_cost,
'currency' => 'PKR',
'min_delivery_date' => $on_min_date,
'max_delivery_date' => $on_max_date
)
));
// encode into a json response
$json_output = json_encode($output);
// log it so we can debug the response
file_put_contents($filename.'-output', $json_output);
// send it back to shopify
print $json_output;
Change According to you needs

Edit woocommerce Login register page

I am using woocommerce for an eCommerce website. I want to add one more field in Login Regiser page. On this page there are three fields in registration (Email, Password and Re-enter password) and I want to add one more field for phone number.
Can anybody help me ? Thanks in Advance
http://wordpress.org/plugins/woocommerce/
If anyone else is curious on how to add additional fields to the login/register/any other account forms. You can achieve this quite easily since WooCommerce has added those to their templates folder. All you have to do is copy-paste the form you need to modify from plugins>woocommerce>templates>myaccount and drop it into your own theme. After which, you can add your extra fields and add any other functionality to make them work using http://docs.woothemes.com/document/hooks/
Hope this is of help to anyone who's been stuck on this.
I Use the "Register Plus Redux" plugin and use the "billing_phone" Database key to map to the correct field in the the User database. You can also have the user add other Information such as "'billing_address_1" and any others.
Best Regards
Marc
Old post, but this answer deals with the question as asked and provides a direct answer form the WordPress Codex
I have modified the code from the pages linked to act inline with the zipcode example that appears on the validation page. Each page within the codes used different examples, I just made them all the same.
Add the custom field
Plugin API/Action Reference/register form
The 'register_form' action hook is used to customize the built-in WordPress registration form.
Use in conjunction with 'registration_errors' (for validation) and 'register_post' (save extra data) when customizing registration.
WordPress MS Note: For Wordpress MS (Multi-Site), use the 'signup_header' action to redirect users away from the signup. (emphasis mine, took me a while to realise this)
Example
This example demonstrates how to add a new field to the registration form. Keep in mind that this won't be saved automatically. You will still need to set up validation rules and manually handle saving of the additional form fields.
add_action( 'register_form', 'myplugin_add_registration_fields' );
function myplugin_add_registration_fields() {
//Get and set any values already sent
$zipcode = ( isset( $_POST['zipcode'] ) ) ? $_POST['zipcode'] : '';
?>
<p>
<label for="user_extra"><?php _e( 'Extra Field', 'myplugin_textdomain' ) ?><br />
<input type="text" name="user_extra" id="user_extra" class="input" value="<?php echo esc_attr( stripslashes( $zipcode ) ); ?>" size="25" /></label>
</p>
<?php
}
link: https://codex.wordpress.org/Plugin_API/Action_Reference/login_form
Validation
You need to validate the user input (obviously) and should run that throughregistration_errors filter hook. Be mindful, the $errors variable may already be populated by other errors from the registration process. As in the examples, you would add your error to errors already contained therein.
Returning an Error
function myplugin_check_fields( $errors, $sanitized_user_login, $user_email ) {
$errors->add( 'demo_error', __( '<strong>ERROR</strong>: This is a demo error.', 'my_textdomain' ) );
return $errors;
}
add_filter( 'registration_errors', 'myplugin_check_fields', 10, 3 );
Validating a Custom Field
(this next section deals specifically with validation of the custom field)
Assuming you wanted to validate a postal code field that you have already created using the register_form hook, you might validate the field like so:
function myplugin_check_fields( $errors, $sanitized_user_login, $user_email ) {
if ( ! preg_match('/[0-9]{5}/', $_POST['zipcode'] ) ) {
$errors->add( 'zipcode_error', __( '<strong>ERROR</strong>: Invalid Zip.', 'my_textdomain' ) );
}
return $errors;
}
add_filter( 'registration_errors', 'myplugin_check_fields', 10, 3 );
link: https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_errors
finally, don't forget to save the custom field's data!
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
if ( isset( $_POST['zipcode'] ) )
update_user_meta($user_id, 'zipcode', $_POST['zipcode']);
}
link: https://codex.wordpress.org/Plugin_API/Action_Reference/user_register
A complete example
At the end of all this I ended up coming across a tutorial to do exactly this. In this example they are adding a First Name field:
//1. Add a new form element...
add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {
$first_name = ( ! empty( $_POST['first_name'] ) ) ? sanitize_text_field( $_POST['first_name'] ) : '';
?>
<p>
<label for="first_name"><?php _e( 'First Name', 'mydomain' ) ?><br />
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr( $first_name ); ?>" size="25" /></label>
</p>
<?php
}
//2. Add validation. In this case, we make sure first_name is required.
add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) {
$errors->add( 'first_name_error', sprintf('<strong>%s</strong>: %s',__( 'ERROR', 'mydomain' ),__( 'You must include a first name.', 'mydomain' ) ) );
}
return $errors;
}
//3. Finally, save our extra registration user meta.
add_action( 'user_register', 'myplugin_user_register' );
function myplugin_user_register( $user_id ) {
if ( ! empty( $_POST['first_name'] ) ) {
update_user_meta( $user_id, 'first_name', sanitize_text_field( $_POST['first_name'] ) );
}
}
https://codex.wordpress.org/Customizing_the_Registration_Form

Can't update product in magento module

have an issue updating magento product from frontend using a module that its function is for customers to create their own products and have the admin approve before enabled(this part is working).
the problem is when a customer tries to updated their admin approved product (as before approval, product states that newly created product is pending, but they can still update the data/attributes created during the product create function, the same attributes that are not updating using the controller)
first of all i have a controller with the action to update the approved/pending customer product
public function editPostAction() {
$id = $this->getRequest()->getParam('productid');
if ( $id !== false ) {
list($data, $errors) = $this->validatePost();
if ( !empty($errors) ) {
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
$this->_redirect('customer/products/edit/', array(
'id' => $id
));
} else {
$customerId = $this->_getSession()->getCustomer()->getid();
$product = Mage::getResourceModel('customerpartner/customerpartner_product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('customer_id', $customerId)
->addAttributeToFilter('entity_id', $id)
->load()
->getFirstItem();
$product->setName($this->getRequest()->getParam('name'));
$product->setSku($this->getRequest()->getParam('sku'));
$product->setDescription($this->getRequest()->getParam('description'));
$product->setShortDescription($this->getRequest()->getParam('short_description'));
$product->setPrice($this->getRequest()->getParam('price'));
$product->setWeight($this->getRequest()->getParam('weight'));
$product->setStock($this->getRequest()->getParam('stock'));
$product->save();
if ( isset($_FILES) && count($_FILES) > 0 ) {
foreach($_FILES as $image ) {
if ( $image['tmp_name'] != '' ) {
if ( ( $error = $this->uploadImage($image, $id) ) !== true ) {
$errors[] = $error;
}
}
}
}
if ( empty($errors) ) {
$this->_getSession()->addSuccess($this->__('Your product was successfully updated'));
} else {
$this->_getSession()->addError('Product info was saved but was imposible to save the image');
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
}
$this->_redirect('customer/products/');
}
}
}
as well as a form that on submit is supposed to update the product attributes and images but the page reloads on submit and shows successful saved message but the attributes are not updated and going back to the edit form (for each product created) for that product the values in the update form have the values of the update we just submitted, bet yet the products attributes are not updated in the catalog either (they remain the same values as entered in the create new process)
don't no if to continue to figure out what is going wrong or just move to either use api or direct sql to get the job done.
see this post Magento 1.7: Non-system product attribute not saving in PHP script the problem maybe different but the solution can be found in that post
updated to a new action to call in .phtml see below as it seems to be updating the product data as needed, still wanting to improve..
called in form using /frontendname/editApprovedPost/
public function editApprovedPostAction() {
$id = $this->getRequest()->getParam('productid');
$idproduct = $this->getRequest()->getParam('product_id');
if ( $id !== false ) {
list($data, $errors) = $this->validatePost();
if ( !empty($errors) ) {
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
$this->_redirect('customer/products/edit/', array(
'id' => $id
));
} else {
- now added more php code to action (in this order) after the } else {...
require_once 'app/Mage.php';
then add admin store for frontend product updates...
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
then get the customer id...
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
then use the forms product Id to get the Product Id to update...
$product = Mage::getModel('catalog/product')->load("".$idproduct."");
then use setName() to update/save the attribute value grabbed from the forms input value...
$product->setName($this->getRequest()->getParam('name'));//use whatever attributes need (only text and text area tested so far)
then save/update product data with...
$product->save();
then add to run through errors...
if ( empty($errors) ) {
$this->_getSession()->addSuccess($this->__('Your product was successfully updated'));
} else {
$this->_getSession()->addError('Product info was saved but was imposible to save the image');
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
}
$this->_redirect('customer/products/');
}
}
}
then with a form to submit in frontend with customer logged in and customer group config
custom form only visible to Customer Group 2 (default is Wholesale)
form below....
sorry cant paste form to much work to paste the code here, any way using the
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
which i have read in some posts is that to update product in frontend you need to be "admin", which this seems to do just fine. As Noted before, the script was not updating and it was because it is trying to save to a different models data when the data to be updated was an actual product (that has been approved and created using the different models data) and it was updating using
$product = Mage::getResourceModel('customerpartner/customerpartner_product_collection')
would be good to here anyone else's comments
hope this helps someone because was think time to close this build.