Skip to content

Instantly share code, notes, and snippets.

View lucasstark's full-sized avatar

Lucas Stark lucasstark

View GitHub Profile
@lucasstark
lucasstark / gravity-forms-product-addons-custom-export-fields.php
Created February 21, 2019 16:44
Custom export fields for WooCommerce Gravity Forms Product Addons
add_filter( 'gform_export_fields', 'custom_add_wc_order_fields', 10, 1 );
add_filter( 'gform_export_field_value', 'custom_export_wc_order_fields', 10, 4 );
function custom_add_wc_order_fields( $form ) {
array_push( $form['fields'], array(
'id' => 'woocommerce_billing_address_1',
'label' => __( 'WooCommerce Billing Address 1', 'wc_gf_addons' )
) );
array_push( $form['fields'], array(
@lucasstark
lucasstark / gravityforms-woocommerce-tax-display.php
Last active May 6, 2019 13:39
Include Tax Display for Gravity Forms when WooCommerce is set to enter prices exclusive of tax, but show inclusive.
add_filter( 'woocommerce_add_cart_item_data', 'remove_adjust_for_tax_display', 10, 1 );
add_filter( 'woocommerce_get_cart_item_from_session', 'remove_adjust_for_tax_display', 10, 1 );
add_filter( 'woocommerce_get_item_data', 'remove_adjust_for_tax_display', 10, 1 );
add_filter( 'woocommerce_add_cart_item', 'remove_adjust_for_tax_display', 10, 1 );
add_action( 'woocommerce_checkout_create_order_line_item', 'remove_adjust_for_tax_display', 10, 1 );
add_filter( 'woocommerce_add_to_cart_validation', 'remove_adjust_for_tax_display', 99, 1 );
function remove_adjust_for_tax_display( $arg ) {
if ( isset( $_POST['gform_old_submit'] ) ) {
@lucasstark
lucasstark / gravity-forms-product-addons-remove-price.php
Created January 8, 2019 16:43
Attempt to remove GRavity Form price labels from items added to the WooCommerce cart.
add_filter( 'woocommerce_gforms_get_item_data', function ( $data, $field, $lead, $form_meta ) {
if ( strpos( $data['display'], '(' ) !== false && strpos( $data['display'], ')' ) !== false ) {
$data['display'] = substr( $data['display'], 0, strpos( $data['display'], '(' ) );
}
return $data;
}, 10, 4 );
@lucasstark
lucasstark / add-gravity-form-to-all-products.php
Last active March 6, 2021 00:27
Attach a Gravity Form to all WooCommerce products in a category
add_filter( 'woocommerce_gforms_get_product_form_data', 'woocommerce_gforms_get_product_form_data_for_category', 10, 2 );
function woocommerce_gforms_get_product_form_data_for_category( $default_data, $product_id ) {
$products_to_exclude = array();
//uncomment the following line and modify the 10 to a product ID you need to exclude from having this form.
//you can add more if needed.
//$products_to_exclude[] = 10;
@lucasstark
lucasstark / disable-dynamic-pricing-with-coupons.php
Created January 3, 2019 12:17
Disable Dynamic Pricing with Coupon
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'dynamic_pricing_is_product_eligible', 10, 1 );
function dynamic_pricing_is_product_eligible( $apply ) {
//Change these to the codes that should disable dynamic pricing. Add or remove as needed.
$coupon_codes = array(
'cart discount',
'another code',
'third code'
);
@lucasstark
lucasstark / woocommerce-dynamic-pricing-and-product-addons.php
Last active January 2, 2019 17:40
Add WooCommerce Product Addon full costs to Dynamically Adjusted Price
class WC_Dynamic_Pricing_Product_Addons_Compatibility {
private static $instance;
public static function register() {
if ( self::$instance == null ) {
self::$instance = new WC_Dynamic_Pricing_Product_Addons_Compatibility();
}
@lucasstark
lucasstark / cart-item-data.php
Created October 26, 2018 16:56
Output Gravity Forms Image Uploads as an image in the cart.
<?php
/**
* Cart item data (when outputting non-flat)
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cart-item-data.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@lucasstark
lucasstark / functions.php
Created September 14, 2018 16:23
Manually Enqueue Gravity Forms scripts for Gravity Forms Product Addons
<?php
add_action( 'wp_enqueue_scripts', 'add_gravity_forms_scripts' );
function add_gravity_forms_scripts() {
if ( ! class_exists( 'WC_GFPA_Main' ) ) {
return;
}
@lucasstark
lucasstark / addons.js
Created August 14, 2018 13:25
Rough helper to run product addons values though Dynamic Pricing.
jQuery( document ).ready( function($) {
$.fn.init_addon_totals = function() {
function isGroupedMixedProductType() {
var group = $( '.product-type-grouped' ),
subs = 0,
simple = 0;
if ( group.length ) {
(function($) {
$(document).ready(function() {
$("input[type=radio]").click(function() {
// Get the storedValue
var previousValue = $(this).data('storedValue');
// if previousValue = true then
// Step 1: toggle radio button check mark.
// Step 2: save data-StoredValue as false to indicate radio button is unchecked.
if (previousValue) {
$(this).prop('checked', !previousValue);