woocommerce checkout country - wordpress

Hi and thanks in advance for any help,
I need to debug the woocommerce checkout page in which some fields of the form billing are not aligned correctly for some countries.
i saw that the issue is resolved if i add a after the postcode field, the function woocommerce_form_field( $key, $args, $value = null ) adds that div if $args['clear'] is not empty and it's called in a foreach for the checkout page in the checkout/form-billing.php file.
woocommerce_form_field(...) is in woocommerce/includes/wc-template-functions.php.
The $args contains the clear attribute correctly and woocommerce_form_field returns the field with div correctly (mailed myself the data from the function), when i get to the page the div is not there and fields are not aligned. Also i noticed that if i try to echo something it doesn't appear on the page source but if i mail the data from the same form-billing.php spot the data is received correctly.
How can i make the div show correctly ? What javascript could rewrite the form and where can i edit it ?
the fields disaligns if you select United States in the country select.
Any suggestion would be appreciated
P.S.: i added some javascript that adds the div on document.onload but it feels dirty and i'm not sure it works in every case.
EDIT: rephrase, clarify

To be safe when updating woocommerce in future versions you should do the following:
Best is to replace checkout.min.js with your own modified version.
Placing this in your functions.php should load your modified script
$wp_scripts->registered[ 'wc-checkout' ]->src = get_stylesheet_directory_uri() . '/js/yourmodifiedcheckout.js';
Hope this helps, let me know if you need further help.

Related

how to display woocommerce product tags on single product page.?

I'm looking like a crazy person if there is a way to display the tags of a product on the single product page with woocommerce ( wordpress plugin). I can not find anything about ti and I've been trying to tweak the code, but without success . . .
if anybody has some high lite, it will be wonderful,
thank you very much
Ok, so depending on the WordPress theme you use, they might show automatically (just checked and it works right away with the "official" Storefront theme).
If you're writing a plugin (or a theme) though, you're most likely to want the PHP solution. In that case, according to this, you should be good to go with the following:
global $product; // gets the Product object (correspoding to the single page)
$product->get_tags( $product ); // returns an array with product tags
According to this post, you have to use get_terms('product_tag').

remove custom meta boxes not working

what I was trying to do here is to remove some custom fields that I created when a template is selected, aka when I select certain template I want to hide or show specific metaboxes.
The code I have is the following but it isn't working at all (thats to say that it doesn't remove any metaboxes) and I would like help to see what's wrong with it or if what I'm trying to do it's just not posible.
add_action('admin_init','my_meta_init');
function my_meta_init(){
$template_file = get_post_meta(get_the_ID(), '_wp_page_template', TRUE);
if (($template_file == 'thanks-template.php') || ($template_file == 'view-template.php'))
{
remove_meta_box('my_meta_box_id','page','normal');
remove_meta_box('my_meta_box_id_2','page','side');
remove_meta_box('my_meta_box_id_3','page','side');
remove_meta_box('dynamic_sectionid','page','normal');
} else
{
remove_meta_box('my_meta_box_id_4','page','normal');
}
}
Thanks you for the comments and answer, everyone helped. The problem was on the hook I was using, I changed it and now it's working perfectly :
add_action('admin_head','my_meta_init');
You may need to change the HOOK you are using to hook in your function.
That is you need to hook into admin_menu instead of admin_init as the metaboxes might not exist the moment you are trying to remove them. So a certain order is needed to make sure metaboxes removal call is made when actual metaboxes are generated and exist.
I tested following code on my localhost and it hid the Author div/metabox fine when used this code snippet:
function remove_page_fields() {
remove_meta_box( 'authordiv' , 'page' , 'normal' ); //removes author
}
add_action( 'admin_menu' , 'remove_page_fields' );
Another Approach:
By the way, as I think about the situation you are facing, maybe add the metaboxes/custom fields in such a way, that they are shown only to the pages we are meant to. I have worked on projects where I need to show some metaboxes only when certain template is selected.
I use CMB2 class to generate metaboxes mostly, if you happen to use that or something similar, you may use this parameter to specify the page templates https://github.com/WebDevStudios/CMB2/wiki/Display-Options#limit-to-specific-page-templates

wordpress: change order of publish meta box

I'm building a site with WP and the Event Manager plugin, which adds several meta boxes. Client wants all meta boxes to be in one column. No problem there.
But the Publish meta box is like the second or third box. Way too high in the page, and above many of the Events Manager meta boxes.
I can "remove/add" the Publish meta box using the functions.php file, but no combination of $context & $priority variables move it lower in the page.
I have tried hacking the edit-form-advanced.php file in wp-admin, but there does not appear to be anything in there that controls the position of the Publish box.
I have even tried a met box order plugin but no help.
I'm sure you all agree that having the Publish meta box near the top of the form is unacceptable.
Any ideas?
I'm also posting to the Events Manager support thread, but hoping for some help here also.
After additional searching and experimentation, this code added to the functions.php file in the theme got the Events Manager boxes in the desired order...
add_filter( 'get_user_option_meta-box-order_event', 'metabox_order' );
function metabox_order( $order ) {
return array(
'normal' => join(
",",
array( // Arrange here as you desire
'event-categoriesdiv',
'em-event-when',
'em-event-where',
'em-event-attributes',
)
),
);
}

Wordpress: How to pass additional Content to the blog-preview page?

For each blog-post on my wordpress-blog I'd like to have Teaxtarea where i can pass additional content for that post.
In my case that would be an unordered list which contains a quick overview of the content.
That additional content should be displayed in the preview of the post on the blog-preview-page.
My problem:
I am actually not sure on how to best add this additional content and then pass it to the preview.
Do I use wordpress' custom fields for something like this?
I'm gratefull for a push in the right direction.
Thank you,
Nils
If I understand you right, I'd take a look at "custom meta boxes" functionality - it allows you to add any type of additional input into your blog post admin area, and than display its content on front-end however you like.
There's a nice tutorial series on that topic, with example code snippets:
http://wp.tutsplus.com/series/reusable-custom-meta-boxes/
And if you'd like to display the textarea content only in preview mode, you can use appropriate conditional tag in you template file:
http://codex.wordpress.org/Conditional_Tags#A_Preview
The conditional tag is_preview returns true when a single post is viewed in Draft mode. The following will append post meta to the content when a post is being previewed:
function so16799607_preview( $content )
{
if ( ! is_preview() )
return $content;
return $content . get_post_meta( get_the_ID(), 'my_post_meta', true );
}
add_filter( 'the_content', 'so16799607_preview', 10, 1 );
You should check out Advanced Custom Fields. That's a really stable plugin that lets you create custom meta boxes in posts, pages and custom post types. That plugin does exactly what your question states. Need al little PHP to get stuff from your database, but that is as easy as:
<?php the_field(field_name);?>
And the documentation is pretty good. And if you don't like a plugin, it exports the PHP as well.
Anther tool that does the same is Pods Framework. Both powerfull extensions to any WP install in my opinion.
Hope this helps.

Making a plugin operate through a shortcode

Many plugin need some [shortcode] to be placed in a page, sometimes within the loop. But usually it only makes the actual [shortcode] appear where I placed it and nothing else !
For example such and such contact form plugin asks me to put [contact form plugin] in my contact page and I'm supposed to see a form appearing there as a result, but instead I see a blank page with the shortcode appearing.
I'm relatively new to WordPress so this question must sound stupid, stil can anybody take the pain to explain to me ?
AFAIK, [shortcode] is intended to be appeared or operated within the loop. if you want it to display outside it (says, on sidebar, or on footer) you need to manually compute it's value.
To do that, you can use do_shortcode() function:
<?php echo do_shortcode ( '[your-shortcode-text]' ); ?>

Resources