Skip to content

Instantly share code, notes, and snippets.

View dryan1144's full-sized avatar

David Ryan dryan1144

View GitHub Profile
@dryan1144
dryan1144 / edd_update_payment_status.php
Created November 26, 2020 07:37
EDD callback for payment status updates
<?php
/***
Actions after purchase status is changed - useful for check payments
***/
function drw_edd_after_check_purchase( $payment_id, $new_status, $old_status ) {
//bail if the order isn't approved
if ( !in_array($new_status, array('publish', 'complete')) ) {
<?php
/***
Allow a product to be added only once to cart
***/
function drw_edd_one_item_checkout( $download_id, $options ) {
if ( edd_item_in_cart($download_id) ) {
@dryan1144
dryan1144 / post-meta-transient.php
Last active December 24, 2019 20:12
Stores transient in post meta
<?php
/***
Stores persisent data as post meta instead of using Transient API
@param $post_id int post ID to store post meta for
@parm $meta_key str "transient" name
@param $update_func str function to update the meta key with a new value
@param $expiration time when value should expire
@dryan1144
dryan1144 / delete-transients.php
Last active December 24, 2019 20:11
Clear transient on post save
<?php
function yournamespace_delete_transient( $post_id, $post, $update ) {
delete_transient('yournamespace_data_example');
}
//{your_post_type} with a custom post type
add_action('save_post_{your_post_type}', 'yournamespace_delete_transient', 10, 3);
@dryan1144
dryan1144 / setup-meta-transient-rest-api.php
Created December 24, 2019 18:08
Define basic custom field and callback function
<?php
/***
Register custom field for existing endpoint with callback function
Endpoint: /wp/v2/your_post_type
Note: Could also be a custom endpoint using register_rest_route
***/
register_rest_field('your_post_type', 'custom_field_name', array(
@dryan1144
dryan1144 / wp-rest-transient-example.php
Last active December 24, 2019 08:20
Sets a transient for elements in a WP REST API call
<?php
function yournamespace_rest_transient_example() {
//check for transient first
$data = get_transient( 'yournamespace_data_example' );
if ( !empty( $data ) ) {
$data = $terms_transient;
@dryan1144
dryan1144 / woocommerce-functions.php
Last active December 25, 2018 15:45
Change WooCommerce order confirmation text in
<?php
add_filter( 'woocommerce_thankyou_order_received_text', 'my_custom_order_received_text' );
function my_custom_order_received_text() { ?>
<div class="order-received-text">
<h5>Your Order Was Successful!</h5>
<p>Congratulations and a huge thank you for registering with us!</p>
<p>You will receive a confirmation email shortly. If you have questions, please do not hesitate to <a href="/contact">contact us</a></p>
<p>Thanks again!</p>
@dryan1144
dryan1144 / filter-taxonomy-term-url.php
Created July 26, 2017 00:13
Filter taxonomy term URLs for SF Pro
<?php
function hck_filter_taxonomy_archives( $url, $sfid) {
if (is_tax('topics')) {
$slug = get_queried_object()->slug;
$url = site_url() .'/'. get_post_type() .'/'. $slug;
}
return $url;
<?php
function hck_filter_taxonomy_archives( $query_args, $sfid ) {
if( $sfid == 509 ) {
$query_args = array(
'post_type' => 'articles',
);
<?php
function hck_rewrite_post_types() {
add_rewrite_rule('^articles/([^/]*)/?','index.php?post_type=articles&topics=$matches[1]','top');
add_rewrite_rule('^questions/([^/]*)/?','index.php?post_type=questions&topics=$matches[1]','top');
add_rewrite_rule('^amas/([^/]*)/?','index.php?post_type=amas&topics=$matches[1]','top');