I'm developing a plugin that adds a shipping method that accepts rules for calculating shipping cost, some of those rules are the post codes and the zone. How can i access the data that is configured in the image below?
I know i can make a query to the database at woocommerce_shipping_zone_locations but i was wondering if there is a better way using the woocommerce api.
This might be what you need.
<?php
$shipping_zones = WC_Shipping_Zones::get_zones();
echo '<pre>';
print_r($shipping_zones);
echo '</pre>';
?>
Related
I'm wondering whether if I can check a specific cron job is working or not. For example, I would like to send myself an email if the wpse_twicedaily_cron and wpse_oncedaily_cron is not active/ running in the WP.
I can setup the email, but I just need to figure out how to detect if certain cron job is active. I will need to check if the cron jobs are working every 5 minutes.
Thank you!
To view all scheduled tasks, you can use the code below that utilizes _get_cron_array(). Sample code is taken from here
function bl_print_tasks() {
echo '<pre>'; print_r( _get_cron_array() ); echo '</pre>';
}
bl_print_tasks();
You can then create your hook and function and add it as a cron to wordpress.
add_action( 'wpb_custom_cron', 'wpb_custom_cron_func' );
function wpb_custom_cron_func() {
// Check whatever here and then email
wp_mail( 'you#yourdomain.com', 'Cron Alert Email', 'Automatic scheduled email from WordPress to test certain cronjobs');
}
To add your own cron or simply see / trigger other crons, you can use WP Control plugin. Here is how to add your cron from Tools ยป Cron Events
Screenshot and sample mail code taken from here
I am using dokan for my client's website. they want to show map locations of all the vendors if they are in the same city. For example, if you select London then it should show a map of London, and makers should be there on google map. I have done with the map part. I want to get the addresses of all vendors which are there in London. How to do this?
we can get the addresses of the sellers by using the below code.
function test_users(){
$sellers = dokan_get_sellers();
foreach ($sellers['users'] as $seller) {
$store_info = dokan_get_store_info($seller->ID);
echo "<br>";
echo $store_info['address']['street_1'].' '.$store_info['address']['street_2'].'
'.$store_info['address']['city'].' '.$store_info['address']['zip'];
}
}
add_shortcode('test','test_users');
You can use this shortcode[test] to show the addresses.
I brought http://www.woothemes.com/products/paypal-express/ plugin for my wordpress site running woocommerce. But the shipping cost is not including during paypal express checkout.
I checked all setting in woocommerce shipping. I also checked other payment gateways they are including shipping cost
Can anyone please suggest how to include shipping cost in paypal express checkout for woocommerce.
The only way to do this is to edit the actual code in the plugi files woocommerce-gateway-paypal-express.php, Basically what I did was use the cart->get_cart_shipping_total() from the file. Unfortunately it comes formatted with html so I had to just explode out a couple things, I"ve included the code below.
$shipping = WC_PayPal_Express_Compatibility::WC()->cart->get_cart_shipping_total();
$shippingarray = explode(";", $shipping);
$shippingarray = explode("</span>", $shippingarray[1]);
$shippingamt = str_replace("_",".", $shippingarray[0]);
$nvpstr .= "&PAYMENTREQUEST_0_SHIPPINGAMT=" . $shippingamt;
Then you also have to edit the total amount line as well to:
$nvpstr .= "&PAYMENTREQUEST_0_AMT=" . number_format($order_total + $shippingamt, 2);
I have something a client wants me to build, and I can with wp_mail, but I am wondering if how it should be built is fessable - no they dont want to use third party websites or software.
Essentially a widget will take in the clients email address, with this we can:
Have some kind of interface so we can say that send out 5, 10, 15 posts of category x, y, x on a daily, weekly or monthly basis
Thats not hard, but the question is: how would I store the emails that come in? a new column?
Use these emails and a custom post type to create email templates, newsletters and so on that could be sent to a set of emails (in this case all emails stored for now) at a specified time.
This one isn't hard either, its the custom post type part, how would I create a custom post type that when a post is published the post is not published the same way a post is, or a page. but instead its stored like one, but I can use its content in an email body instead of displaying it like a post or page.
essentially I shouldn't be able to go to:
site.come/email_templates/post_id
So the second one is a bit more complicated but I am wondering how you guys might approach this situation or idea.
Here are some thoughts when it comes to the e-mail subscription part. As for the custom post types - I don't have much experience with those, sorry :)
If you want a quick and easy solution for the e-mail subscriptions, create a wp option (see http://codex.wordpress.org/Function_Reference/add_option) that is essentially a hash table that maps categories to keys in the table.
For each category in the hash table, store an array of userIDs and/or e-mails of the users that are subscribed to that category.
Once you have this data structure in place, it's fairly easy to manipulate and use in with wp_mail. Here is some example code that I've written for one of my plugins:
$subscribers = get_option('subscribers');
$categories = get_the_category($post->ID);
if( !empty($categories) && !empty($subscribers)){
$emails = array();
//Go through each category and accumulate the necessary e-mail addresses
foreach($categories as $category){
$catID = $category->term_id;
if( !empty($subscribers[$catID]) ){
foreach($subscribers[$catID] as $userID => $trash){
$user = get_userdata($userID);
$userEmail = array( $userID => $user->user_email );
if( !in_array($userEmail, $emails) ){
$emails = $emails + $userEmail;
//you can use something like implode(", ", $emails)
//in the Bcc: part when you send out the e-mail.
}
}
}
}
}
Some things to note:
This is a quick and dirty solution. If the number of categories and number of subscribers grows big, you're better of creating a table in the database and maintaining it that way
Make sure to think of situations when categories are deleted (i.e. hook into actions when categories are deleted) and how that will affect your datastructure
The hash table approach works well assuming categories are NOT deleted/added frequently
Good luck!
How can I allow non users to delete posts?
I am currently using this code:
<?php
global $wp_query;
$cat = get_the_category();
if ($cat[0]->cat_ID == 86){
$url = get_bloginfo('url');
echo "<a>ID) . "'>Delete post</a>";
}
?>
This adds a delete link if the current post is in a certain category. It works perfectly but It requires a user with edit privileges to be logged in. How can I change this to allow for regular, non registered users to delete posts?
Any help is appreciated.
You have two options:
1) Promote non-users into users by giving them a session to uniquely identify them and relate each poster with their posts. This requires additional session storage for non-users.
2) Generate a unique hash for each post and provide in the view page a once-only option to delete the post. Similarly to imgur.com, they can still delete the post if they saved the link but will not be presented again. This saves server state.