Created
October 3, 2017 08:45
-
-
Save unwiredtech/043d7f24c2cf137dd2e5d055db5c5bdb to your computer and use it in GitHub Desktop.
woocommerce-get-purchase-link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
==================================================================== | |
Adding Purchase Link to Woocommerce Product in Wordpress Dashboard | |
==================================================================== | |
*/ | |
if (is_admin()) { | |
add_action('admin_print_scripts', 'add_direct_checkout_link'); | |
function add_direct_checkout_link() { | |
?> | |
<script> | |
addLoadEvent(function () { | |
jQuery(document).ready(function () { | |
var post = jQuery('#post'), | |
postType = post.find('#post_type').val(), | |
purchaseLink = post.find('#sample-permalink > a').attr('href') + '?purchase=1'; | |
if (postType !== 'product') { | |
return; // Do not proceed you have nothing to do in here | |
} | |
jQuery('#edit-slug-box').append('<span id="view-post-btn"><a onclick="prompt(\'URL:\', \'' + purchaseLink + '\'); return false;" class="button button-small">Purchase Link</a></span>'); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
} | |
/** | |
* Front Page | |
* **************************************************************************** */ | |
add_action('wp', 'process_purchase_link'); | |
function process_purchase_link() { | |
if (is_product() && $_GET['purchase'] == 1) { | |
WC()->cart->add_to_cart(get_the_ID(), 1); | |
wp_redirect(WC()->cart->get_checkout_url()); | |
die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment