Modification of get attribute variable upgrade? - woocommerce

Took me a while to find a solution for having 3 variable subscription products and being able to use a direct link (button) to go straight to the checkout when clicked.
BUT... Now I'm faced with an issue. Since I only allow 1 variable product it gives me a white page in 2 cases:
When I put to manual renewal for people to be able to renew using a bank account or crypto
When people initially use pay by the bank and never actually complete the purchase. (if they come back and click choose button to purchase they get a white screen)
Please... I would really appreciate the solution.
add_action( 'woocommerce_after_single_product_summary', 'aaaa', 20 );
function aaaa()
{
if (isset($_GET['attribute_type'])) {
?>
<script>
jQuery(document).ready(function(){
setTimeout(function() { jQuery(".single_add_to_cart_button").trigger("click"); }, 1000);
});
</script>
<style type="text/css">
html{
display: none!important;
}
</style>
<?php
}
}
add_filter ('woocommerce_add_to_cart_redirect', function( $url, $adding_to_cart ) {
return wc_get_checkout_url();
}, 10, 2 );

Related

Hide plugin from admin bar & plugin list

I am trying to hide the following item from the following sections:
Admin bar: ID = wp-admin-bar-nitropack-top-menu
Plugin list: data-slug="nitropack"
I have tried these methods, but can not get it to work. Maybe i have the wrong IDs/Slugs?
Methods: https://divi.space/wordpress-and-divi-code-snippets/hide-any-plugin-from-the-wordpress-dashboard/
Would really appreciate some help, since a customer should not be able to change the settings within this plugin!
Best regards,
Isac
The css way
<style>
a[data-slug="nitropack"] { //hides all a href's with that data slug
display:none;
}
</style>
normally if its an wp admin menu you would do something like this:
//remove admin page item
function edit_admin_menus() {
remove_menu_page("index.php"); //Dashboard
remove_menu_page("itsec"); // wp-admin.php?page=itsec use this "itsec"
}
add_action("admin_menu", "edit_admin_menus");
or you need to remove admin bar item
//remove tool bar item
function remove_toolbar_node($wp_admin_bar) {
// replace 'updraft_admin_node' with your node id "nitropack" something
$wp_admin_bar->remove_node("avia");
$wp_admin_bar->remove_node("updates");
$wp_admin_bar->remove_menu("wp-logo");
$wp_admin_bar->remove_menu("themes");
$wp_admin_bar->remove_menu("widgets");
$wp_admin_bar->remove_menu("dashboard");
//$wp_admin_bar->remove_node("updraft_admin_node");
}
add_action("admin_bar_menu", "remove_toolbar_node", 999);
FYI, since you need to block access to the plugin you'll need to add a redirect based on member role. The customer may know the actual url and can still access the page.
//Admin or Editor role check, if else send to alt url
function block_pages_for_user() {
$blocked_pages = is_page('slug');
$url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if( !current_user_can('administrator') && !current_user_can('editor') && !current_user_can('subscriber') && $blocked_pages ) {
wp_redirect( 'http://www.example.dev/your-page/', 301 );
exit;
}
}
add_action( 'wp', 'block_pages_for_user', 8 );

How to clear form input on page load woocommerce checkout

I am offering customers a repurchase on the order confirmed page. If they click the link they are sended directly to the checkout page. However, the form is then prefilled with the previous data. I would like to clear it, because the idea is one product(ticket) per person.
So far i have the following (and in the page source i can see the script is loaded):
function print_script() {
if (isset($_GET['extrapersoon']) && is_page(21560)){
echo '<script>
window.addEventListener("load", function(){myFunction()};
function myFunction() {
document.getElementsByClassName("woocommerce-checkout").reset();
}
</script>';
}
}
add_action('wp_print_scripts', 'print_script');
I tried other triggers too, such as window.load but no result yet.
Anyone?
You should put the script in the footer using add_action( 'wp_footer', 'print_script' ); to make sure the form gets cleared after the data was loaded into it.
Wordpress has jQuery on default, so I'm using it to look for all the forms in the document and clear them. The function is automatically called on page load, therefore no need for a event listener.
<?php
function print_script() {
if (isset($_GET['extrapersoon']) && is_page(21560)) { ?>
<script type="text/javascript">
( function( $ ) {
$('form').each(function() { this.reset() });
}( jQuery ) );
</script>
<?php }
}
add_action( 'wp_footer', 'print_script' ); ?>

How to hide billing_city field for specific states in woocommerce

i need some help, please. i need to hide billing_city field for specific selected states.
Firstly, i needed it only for 1 state.
Ive been exploring Internet and found the snippet, adopted it for my purpose. As result, it works fine. But now i need to hide the billing_city field for more than 1 state. i would be very grateful if someone could help solve my issue.
Thank you!
//hide billing_city field for 77state
add_action( 'woocommerce_after_checkout_form', 'hide_show_billing_city', 5);
function hide_show_billing_city() {
?>
<script type="text/javascript">
jQuery('select#billing_state').live('change', function(){
var state = jQuery('select#billing_state').val();
var check_state = new Array(<?php echo '"77"'; ?>);
if (state && jQuery.inArray( state, check_state ) >= 0) {
jQuery('#billing_city_field').fadeOut();
} else {
jQuery('#billing_city_field').fadeIn();
jQuery('#billing_city_field input').val('');
}
});
</script>
<?php
}

Move up product data woocommerce on mobile

is there a way ON MOBILE to move the 3 dropdowns section to the above the product name and gallery image?
I am using the woocommerce plugin and for the dropdowns im using the PRODUCT DATA - VAriable product section.
check the link:
Website
I would need more about your actual code (or a demo version) to achieve what you exactly want. You could use a bit of jQuery in your function.php, the following code as not been tested but the logic is there:
/*Move the variation div to another created one
======================================================================= */
add_action( 'wp_footer', 'move_variations_product_tab' );
function move_variations_product_tab() {
if (is_product()) :
$product = wc_get_product( get_the_ID() );
if($product->is_type( 'composite' )){
?>
<script>
jQuery(document).ready(function($) {
$(window).load(function() {
$( ".variations_form" ).wrap( "<div id='variations-content'></div>" );
$( ".woocommerce-product-gallery" ).before( "<div class='container product-before-gallery'></div>" );
document.getElementsByClassName("product-before-gallery")[0].appendChild(
document.getElementById("variations-content")
);
});
});
</script>
<?php
}
endif;
}
Replace "product-short" by the container of your description.
Wrapping around the div you want to move.
Creating a new class before the desired location
Move the wrapped div (#variations-content) under the newly created one
(.product-before-gallery).
Hope that helps! Let me know how it goes and give more info if you needs help.
Cheers

Notice in product page only on selected products in Woo?

I have one issue. How to show notice or text , in product page, only for selected products?
i know that must to insert some function in functions.php, but dont know how to do that. Can anyone give me some dirrections? Thanks
I found this function:
// adds notice at single product page above add to cart
add_action( 'woocommerce_single_product_summary', 'return_policy', 20 );
function return_policy() {
echo '<p id="rtrn">30-day return policy offered. See Terms and Conditions for details.</p>';
}
and CSS:
#rtrn {
text-align: center;
font-style: italic;
}
This function show message in every product, but i need only in selected products..
so how to show this message only on selected products? How to select products where message need to be showed?
Find the id of the product you want the message to appear by hovering on the product name in your product listings or by looking at the URL while editing the product and add the following code in your functions.php file
add_action( 'woocommerce_single_product_summary', 'return_policy', 20);
function return_policy() {
if ( is_single( 'product_id' ) ) {
echo '<p>30-day return policy offered. See Terms and Conditions for details.</p>';
}
}

Resources