Created
February 19, 2019 15:48
-
-
Save plugin-republic/2a5d9903c019790bad44ac680b00bb91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add a text field to each cart item | |
*/ | |
function prefix_after_cart_item_name( $cart_item, $cart_item_key ) { | |
$notes = isset( $cart_item['notes'] ) ? $cart_item['notes'] : ''; | |
printf( | |
'<div><textarea class="%s" id="cart_notes_%s" data-cart-id="%s">%s</textarea></div>', | |
'prefix-cart-notes', | |
$cart_item_key, | |
$cart_item_key, | |
$notes | |
); | |
} | |
add_action( 'woocommerce_after_cart_item_name', 'prefix_after_cart_item_name', 10, 2 ); | |
/** | |
* Enqueue our JS file | |
*/ | |
function prefix_enqueue_scripts() { | |
wp_register_script( 'prefix-script', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'update-cart-item-ajax.js', array( 'jquery-blockui' ), time(), true ); | |
wp_localize_script( | |
'prefix-script', | |
'prefix_vars', | |
array( | |
'ajaxurl' => admin_url( 'admin-ajax.php' ) | |
) | |
); | |
wp_enqueue_script( 'prefix-script' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'prefix_enqueue_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment