Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tharsheblows on github.
  • I am mjjay (https://keybase.io/mjjay) on keybase.
  • I have a public key ASBzB6w1DaikAYyikGjuZyT62E-0D3KqNUoUbBoGk6PsYgo

To claim this, I am signing this object:

@tharsheblows
tharsheblows / allow-resubscribe-cancelled-orders.diff
Created January 13, 2021 10:39
Allow users to resubscribe to cancelled parent subscriptions which have only cancelled resubscription orders. (Based on WooCommerce 3.0.11)
diff --git a/includes/wcs-resubscribe-functions.php b/includes/wcs-resubscribe-functions.php
index 2faea23..b8e94c8 100644
--- a/includes/wcs-resubscribe-functions.php
+++ b/includes/wcs-resubscribe-functions.php
@@ -219,11 +219,23 @@ function wcs_can_user_resubscribe_to( $subscription, $user_id = '' ) {
}
}
- if ( empty( $resubscribe_order_ids ) && $subscription->get_payment_count() > 0 && true === $all_line_items_exist && false === $has_active_limited_subscription ) {
+ // When an order is cancelled, the subscription is cancelled.
@tharsheblows
tharsheblows / failed-payment-limiter-fix.diff
Created January 13, 2021 10:32
This patch is for WooCommerce Subscriptions 3.0.11 and in the WCS_Limiter:: order_awaiting_payment_for_product method. The check to make sure the order includes the product is incorrect.
diff --git a/includes/class-wcs-limiter.php b/includes/class-wcs-limiter.php
index d030723..4fa1e8d 100644
--- a/includes/class-wcs-limiter.php
+++ b/includes/class-wcs-limiter.php
@@ -253,7 +253,7 @@ class WCS_Limiter {
foreach ( $order->get_items() as $item ) {
// If this order contains the product we're interested in, continue finding a related subscription.
- if ( $item['product_id'] == $product_id && $item['variation_id'] == $product_id ) {
+ if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
/** @jsx jsx */
import { jsx } from 'theme-ui'
const CommentsCount = ( { post } ) => {
const commentCount = post.commentCount || 0
return (
<div sx={{ mb: 2 }}>
Comments: { commentCount }
</div>
)
@tharsheblows
tharsheblows / comments-list.js
Created July 25, 2020 09:54
Lists all the comments if given an array of them from the WP REST API.
/** @jsx jsx */
import { jsx, Styled } from 'theme-ui'
import React from 'react'
import Comment from './Comment'
const CommentsList = ({ comments }) => {
const commentCount = ( comments ) ? `${comments.length} ` : ''
const commentHeading =
commentCount > 1 ? 'Comments' : commentCount < 1 ? 'No comments' : 'Comment'
@tharsheblows
tharsheblows / comment.js
Last active July 25, 2020 09:55
Renders one comment if given a comment object from the WP REST API
/** @jsx jsx */
import { jsx } from 'theme-ui'
import React from 'react'
import sanitizeHtml from 'sanitize-html'
import Date from './Date'
const Comment = ({ comment }) => {
const {
/** @jsx jsx */
import { jsx, Styled } from 'theme-ui'
import { useState } from 'react'
const CommentForm = ({ post, commentsEndpoint }) => {
const postId = post.postId
const [userName, setUserName] = useState('')
const [email, setEmail] = useState('')
const [message, setMessage] = useState('')
/** @jsx jsx */
import { jsx } from 'theme-ui'
import React, { useState, useEffect } from 'react'
import CommentsCount from './CommentsCount'
import CommentsList from './CommentsList'
import CommentForm from './CommentForm'
const Comments = ({ post, location, wordPressUrl }) => {
// The comments endpoint, hardcoded in, I have no shame.
const commentsEndpoint = `${wordPressUrl}/wp-json/wp/v2/comments`
<?php
namespace Lalala\Src;
use \Defuse\Crypto\Crypto;
use \Defuse\Crypto\Key;
use Lalala\Src\Debug\Logging;
/**
* Wrapper class for encryption.
@tharsheblows
tharsheblows / class-mjj-menu-functions.php
Created January 18, 2020 19:49
Adding conditional menu items to WordPress menus with custom type labels.
<?php
/**
* Conditional menu items and sane ways to add them to menus in the admin area.
*
* @package mjj_menu
*/
class MJJ_Menu_Functions {
/**
* Our new menu types