Skip to content

Instantly share code, notes, and snippets.

View WPprodigy's full-sized avatar
🖥️
🍕🍕🍕

Caleb Burks WPprodigy

🖥️
🍕🍕🍕
View GitHub Profile
@WPprodigy
WPprodigy / external-product-embed-snippets.php
Last active December 28, 2020 22:00
Short snippets to edit the product data retrieved by the shortcodes.
<?php
/**
* Change the default shortcode button text for both shortcodes
*/
add_filter( 'wcepe_external_product_shortcode', 'wcepe_change_default_button_text' );
add_filter( 'wcepe_recent_external_products_shortcode', 'wcepe_change_default_button_text' );
function wcepe_change_default_button_text( $atts ) {
@WPprodigy
WPprodigy / functions.php
Created February 1, 2017 00:49
Change WooCommerce attribute labels based on the Product ID
add_action( 'woocommerce_attribute_label', 'wc_ninja_change_attribute_label', 20, 3 );
function wc_ninja_change_attribute_label( $label, $name, $product ) {
// Check if on single product page and if the attribute name is 'color'
if ( is_product() && 'color' === $name ) {
global $product;
// Change the label text based on the product ID
switch ( $product->id ) {
case '357':
$label = 'Custom Label One';
@WPprodigy
WPprodigy / functions.php
Last active September 9, 2020 20:55
Co-Author Plus ES query fix
<?php
/**
* Co-Author Plus ES query fix.
*
* With CAP, authors are attached either with the traditional
* author field or via an "author" taxonomy. So we need to check both.
*/
add_filter( 'es_posts_request', function( $es_args, $query ) {
if ( ! $query->is_author() ) {
@WPprodigy
WPprodigy / tracking-code-at-checkout.php
Last active August 19, 2020 20:00
Add analytics tracking to the WooCommerce order received / thank-you page
/**
* Add Tracking Code to the Order Recieved Page
*/
function wc_ninja_checkout_analytics( $order_id ) {
$order = new WC_Order( $order_id );
$currency = $order->get_order_currency();
$total = $order->get_total();
$date = $order->order_date;
?>
<!-- Paste Tracking Code Under Here -->
@WPprodigy
WPprodigy / example.php
Last active July 29, 2020 13:16
Avoid 2FA during JSON API OAuth flow
<?php
/*
* Jetpack's JSON API Authorization flow needs to run free of the 2FA checks.
* JP already does additional validation on top of the normal login, so we can rely on that as the 2fa here.
*
* First we hook into wp_login right before the VIP Two_Factor_Core plugin does.
* Then if the situation is right, remove the additional 2FA login step.
*/
add_action( 'wp_login', function( $user_login, $user ) {
@WPprodigy
WPprodigy / example.php
Last active July 29, 2020 11:07
Prevent 2FA from being enforced for JP JSON API requests.
<?php
// Prevent 2FA from being enforced for JP JSON API requests.
add_filter( 'wpcom_vip_is_two_factor_forced', function( $forced ) {
$current_user = wp_get_current_user();
if ( vip_is_jetpack_xml_rpc_json_api_request() && isset( $current_user->user_login ) && 'example_username' === $current_user->user_login ) {
$forced = false;
}
return $forced;
<?php
if ( ! class_exists( 'WPCOM_VIP_CLI_Command' ) || ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
return;
}
WP_CLI::add_command( 'vip-remove-old-revisions', 'VIP_Remove_Old_Revisions_Command' );
class VIP_Remove_Old_Revisions_Command extends WPCOM_VIP_CLI_Command {
@WPprodigy
WPprodigy / functions.php
Created January 17, 2017 17:14
Unhook cart addons from the cart page in WooCommerce
add_action( 'woocommerce_after_cart_table', 'wc_ninja_remove_cart_addons', 10 );
function wc_ninja_remove_cart_addons() {
global $sfn_cart_addons;
remove_action( 'woocommerce_after_cart_table', array( $sfn_cart_addons, 'cart_display_addons' ), 20 );
}
@WPprodigy
WPprodigy / functions.php
Created March 31, 2016 21:36
Hide a shipping method based on a use role
function wc_ninja_role_base_shipping_method( $rates, $package ) {
// Make sure flat rate is available
if ( isset( $rates['flat_rate'] ) && ! current_user_can( 'wholesale' ) ) {
unset($rates['flat_rate']);
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'wc_ninja_role_base_shipping_method', 10, 2 );
@WPprodigy
WPprodigy / functions.php
Last active December 25, 2019 05:29
Change add to cart url and text for simple products.
add_filter( 'woocommerce_product_add_to_cart_url', 'wc_ninja_edit_add_to_cart_url', 10, 2 );
function wc_ninja_edit_add_to_cart_url( $url, $product ) {
if ( 'simple' === $product->get_type() ) {
$url = $product->get_permalink();
}
return $url;
}
add_filter( 'woocommerce_product_add_to_cart_text', 'wc_ninja_edit_add_to_cart_text', 10, 2 );