Skip to content

Instantly share code, notes, and snippets.

View deivamagalhaes's full-sized avatar

Deiva Magalhaes deivamagalhaes

View GitHub Profile
@deivamagalhaes
deivamagalhaes / messages.json
Last active July 8, 2020 18:29
SkyVerge Messages Sample
[
{
"id": "first-test-message", // required
"datePublished": "2020-07-07", // required
"visibility": { // all optional
"activePlugins": [
"WooCommerce Checkout Add-Ons",
"WooCommerce Local Pickup Plus"
],
"activeThemes": [
@deivamagalhaes
deivamagalhaes / snippet.php
Created June 26, 2020 21:19
Customize AVS mismatch error message
<?php
add_filter( 'wc_payment_gateway_transaction_response_user_message', 'sv_customize_avs_mismatch_message', 10, 3 );
/**
* Customize AVS mismatch error message.
*
* @param string $message message to show to user
* @param string $message_id machine code for the message, e.g. card_expired
* @param SV_WC_Payment_Gateway_API_Response_Message_Helper $helper helper instance
@deivamagalhaes
deivamagalhaes / snippet.php
Created June 23, 2020 17:14
Unset transaction source for Braintree
<?php
add_filter( 'wc_braintree_transaction_data', 'sv_unset_transaction_source', 10, 2 );
/**
* Unset the transaction source to prevent authorizations from expiring too soon.
*
* @param array $request_data The transaction/sale data
* @param \WC_Braintree_API_Transaction_Request $request the request object
* @return array
@deivamagalhaes
deivamagalhaes / snippet.php
Created May 14, 2020 20:17
Increase Facebook feed generation interval to one hour
<?php
add_filter( 'wc_facebook_feed_generation_interval', function( $interval ) {
return HOUR_IN_SECONDS;
} );
@deivamagalhaes
deivamagalhaes / snippet.php
Last active May 14, 2020 19:11
Hide checkout add-on from members - replace my-addon with the name of your add-on
<?php
add_filter( 'woocommerce_checkout_add_on_get_enabled', function( $value, $checkout_add_on ) {
// bail if Memberships is not active
if ( ! function_exists( 'wc_memberships_is_user_member' ) ) {
return $value;
}
@deivamagalhaes
deivamagalhaes / snippet.php
Created April 16, 2020 17:19
Add membership notes to user memberships GET in REST API
<?php
add_filter( 'woocommerce_rest_prepare_wc_user_membership', function ( WP_REST_Response $response, $post, $request ) {
$membership = wc_memberships_get_user_membership( $post->ID );
if ( $membership instanceof WC_Memberships_User_Membership ) {
$data = $response->get_data();
$data['notes'] = $membership->get_notes();
@deivamagalhaes
deivamagalhaes / snippet.php
Last active April 15, 2020 21:59
Allows to sort the packing list excluding a given category tree
<?php
add_filter( 'woocommerce_get_product_terms', function ( $terms, $product_id, $taxonomy, $args ) {
if ( isset( $_GET['wc_pip_action'] ) && ! empty( $_GET['wc_pip_document'] ) && 'packing-list' == $_GET['wc_pip_document'] ) {
$terms = wp_get_post_terms( $product_id, $taxonomy, array(
'orderby' => 'parent',
'order' => 'DESC',
'exclude_tree' => '33',
@deivamagalhaes
deivamagalhaes / restrict_comments.php
Last active April 16, 2020 17:26
Code snippet to hide the comments and the comment form for all non-members
<?php
add_filter( 'comments_array', function ( $comments_flat, $post_id ) {
$post = get_post( $post_id );
// checks if the current post has any restricted content
if ( false !== strpos( $post->post_content, '[wcm_restrict' ) ) {
if ( ! wc_memberships_is_user_active_member()
@deivamagalhaes
deivamagalhaes / snippet.php
Last active July 2, 2020 17:40
Track AddToCart event on Basel theme
<?php
function sv_add_filter_for_conditional_add_to_cart_fragments() {
// only make changes as long as Facebook for WooCommerce is installed
if ( function_exists( 'facebook_for_woocommerce' ) ) {
$events_tracker = facebook_for_woocommerce()->get_integration()->events_tracker;
$events_tracker->add_filter_for_conditional_add_to_cart_fragment();
}
@deivamagalhaes
deivamagalhaes / functions.php
Last active March 13, 2020 21:19 — forked from jdeeburke/functions.php
Jilt support for WooCommerce Phone Orders
<?php
// Add the following snippet to your theme's functions.php file, or use a plugin like Code Snippets.
add_action( 'init', function() {
// Only make changes as long as Jilt for WooCommerce is installed and connected to Jilt
if ( function_exists( 'wc_jilt' ) && wc_jilt()->get_integration()->is_jilt_connected() ) {
// Disable Storefront JS for Phone Order carts