Skip to content

Instantly share code, notes, and snippets.

@grayayer
Created December 1, 2020 04:26
Show Gist options
  • Save grayayer/bc1d819012ba20509d5bf2d4bb6ee63d to your computer and use it in GitHub Desktop.
Save grayayer/bc1d819012ba20509d5bf2d4bb6ee63d to your computer and use it in GitHub Desktop.
WooCommerce Subscription product page with gifted subscriptions checkbox gets auto clicked upon page load.
function auto_select_gift() {
if ( is_single(56669) ) { //enter product id here
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
document.getElementById("gifting_0_option").click(); // Click on the checkbox
});
</script>
<?php
}
}
add_action('wp_head', 'auto_select_gift');
@grayayer
Copy link
Author

grayayer commented Dec 1, 2020

The purpose of this is to make it painfully obvious on a certain product, that it is intended to be used for gifting, rather than buying for oneself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment