Created
March 21, 2019 15:07
-
-
Save shrimp2t/539763fd6858d7135ae95f749242d5fd to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Wishlist_Plus_Product { | |
public function __construct() { | |
add_action( 'woocommerce_single_product_summary', array( $this, 'add_button_hook' ), 35 ); | |
add_action( 'woocommerce_after_shop_loop_item', array( $this, 'add_button_hook' ), 100 ); | |
add_action( 'wp_footer', array( $this, 'wishlist_modal_template' ), 100 ); | |
} | |
public function wishlist_modal_template() { | |
if ( wishlist_plus()->get_limit() <= 1 ) { | |
return; | |
} | |
?> | |
<div id="wislist-plus-overlay"></div> | |
<div id="wislist-plus-modal" class="wislist-plus-modal"> | |
<div class="wlp-modal-inner"> | |
<div class="wlp-modal-heading"><?php _e( 'Add to...', 'wishlist-plus' ); ?><span class="wlp-modal-close"> | |
<span class="wlp-modal-x"></span> | |
</span></div> | |
<ul> | |
<?php foreach ( (array) wishlist_plus()->get_user_wishlists() as $item ) { ?> | |
<li id="mdwlid-<?php echo esc_attr( $item->list_id ); ?>"> | |
<label><input class="wishlist-plus-add-list" value="<?php echo esc_attr( $item->list_id ); ?>" type="checkbox"/> <span><?php echo esc_html( $item->list_name ); ?></span></label> | |
</li> | |
<?php } ?> | |
</ul> | |
<a href="#" rel="nofolow" class="wlp-modal-add-list"><?php _e( 'Create new wishlist', 'wishlist-plus' ); ?></a> | |
<form class="wlp-modal-form"> | |
<div class="wpl-field"> | |
<label><?php _e( 'Name', 'wishlist-plus' ); ?></label> | |
<input type="text" class="wpl-input new-wishlist-name"> | |
</div> | |
<input type="button" class="wpl-button" value="<?php esc_attr_e( 'Create', 'wishlist-plus' ); ?>"> | |
</form> | |
</div> | |
</div> | |
<?php | |
} | |
public function add_button_hook() { | |
global $product; | |
echo $this->add_button( $product, null ); | |
} | |
function add_button( $product = false, $varian_id = false ) { | |
if ( ! $product instanceof WC_Product ) { | |
$product = wc_get_product( $product ); | |
} | |
if ( ! $product instanceof WC_Product ) { | |
return false; | |
} | |
$id = $product->get_id(); | |
$link = wishlist_plus()->get_wishlist_page_url( | |
array( | |
'add_wishlist' => $id, | |
'varian_id' => $varian_id, | |
) | |
); | |
$atts = array( | |
'class' => 'wishlist-plus-add-btn add-to-wishlist p_' . $id, | |
'rel' => 'nofollow', | |
'href' => $link, | |
'data-product_id' => $id, | |
'data-varian_id' => $varian_id, | |
'title' => wp_sprintf( __( 'Add “%s” to wishlist', 'wishlist-plus' ), $product->get_name() ), | |
); | |
$atts = array_filter( $atts ); | |
$atts = apply_filters( 'wishlist_plus_button_args', $atts, $this ); | |
$string = array(); | |
foreach ( $atts as $k => $value ) { | |
$string[ $k ] = "{$k}='" . esc_attr( $value ) . "'"; | |
} | |
$button = '<a ' . join( ' ', $string ) . '>' . __( 'Add to wishlist #', 'wishlist-plus' ) . $id . '</a>'; | |
return $button; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment