$(document).on('click', '.open-popup', function(){
const data = [
{
src: '<span>Текст №1</span>',
type: 'inline'
},
{
src: '<span>Текст №2</span>',
type: 'inline'
},
{
src: '<span>Текст №3</span>',
type: 'inline'
},
]
$.magnificPopup.open({
callbacks: {
elementParse: function(item) {
item.src = data[item.index].src;
}
}
});
});
$args = array(
'posts_per_page' => -1
'tax_query' => array(
'taxonomy' => тут название вашего созданного атрибута (можно посмотреть в url строке, там будет что-то типа taxonomy='brends'),
'field' => 'slug',
'terms' => $_POST['тут что хранится в id или name ваших чекбоксов']
)
);
$brends = new WP_Query( $args );
function load_scripts() {
if (!(wc_get_product() && wc_get_product()->is_type('bundle'))) {
wp_deregister_script( 'wc-add-to-cart-variation' );
wp_register_script( 'wc-add-to-cart-variation', get_template_directory_uri() . '/assets/js/add-to-cart-variation.js', array( 'jquery', 'wp-util' ) );
}
}
'wc-add-to-cart-variation' => array(
'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ),
'deps' => array( 'jquery', 'wp-util', 'jquery-blockui' ),
'version' => WC_VERSION,
),
$regular_price = $product->is_type('variable') ? $product->get_variation_regular_price( 'min', true ) : ( method_exists( $product, 'get_regular_price' ) ? $product->get_regular_price() : $product->regular_price );
if ( !$product->get_sale_price() ) {
if (!$regular_price) {
$regular_price = $regular_variation_price;
$product->get_price() ? $price .= '<span class="price-original">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>' : $price .= '<span class="product-original">Цена не указана</span>';
}
if ( !$product->get_sale_price() ) {
$product->get_price() ? $price .= '<span class="price-original">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>' : $price .= '<span class="product-original">Цена не указана</span>';
} else {
$price .= '<span class="price-sale">' . number_format($sale_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span><span class="product-sale">' . number_format($regular_price, 0, '', ' ') . sprintf( get_woocommerce_currency_symbol() ) . '</span>';
}
in_array() expects parameter 2 to be array
/ New Multi Checkbox field for woocommerce backend
function woocommerce_wp_multi_checkbox( $field ) {
global $thepostid, $post;
$field['value'] = get_post_meta( $thepostid, $field['id'], true );
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
$field['style'] = isset( $field['style'] ) ? $field['style'] : '';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['value'] = isset( $field['value'] ) ? $field['value'] : array();
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
<legend>' . wp_kses_post( $field['label'] ) . '</legend>';
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
echo wc_help_tip( $field['description'] );
}
echo '<ul class="wc-radios">';
foreach ( $field['options'] as $key => $value ) {
echo '<li><label><input
name="' . esc_attr( $field['name'] ) . '"
value="' . esc_attr( $key ) . '"
type="checkbox"
class="' . esc_attr( $field['class'] ) . '"
style="' . esc_attr( $field['style'] ) . '"
' . (array_search($key, is_array($field["value"]) ? $field["value"]:array($field["value"])) !== false ? 'checked="checked"': '' ). ' /> ' . esc_html( $value ) . '</label>
</li>';
}
echo '</ul>';
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
}
echo '</fieldset>';
}
// Add custom multi-checkbox field for product general option settings
add_action( 'woocommerce_product_options_general_product_data', 'add_custom_settings_fields', 20 );
function add_custom_settings_fields() {
global $post;
echo '<div class="options_group hide_if_variable"">'; // Hidding in variable products
woocommerce_wp_multi_checkbox( array(
'id' => '_custom_level',
'name' => '_custom_level[]',
'label' => __('Levels', 'woocommerce'),
'options' => array(
'MBO' => __( 'MBO', 'woocommerce' ),
'HBO' => __( 'HBO', 'woocommerce' ),
'WO' => __( 'WO', 'woocommerce' )
)
) );
echo '</div>';
}
// Save custom multi-checkbox fields to database when submitted in Backend (for all other product types)
add_action( 'woocommerce_process_product_meta', 'save_product_options_custom_fields', 30, 1 );
function save_product_options_custom_fields( $post_id ){
if( isset( $_POST['_custom_level'] ) ){
$post_data = $_POST['_custom_level'];
// Data sanitization
$sanitize_data = array();
if( is_array($post_data) && sizeof($post_data) > 0 ){
foreach( $post_data as $value ){
$sanitize_data[] = esc_attr( $value );
}
}
update_post_meta( $post_id, '_custom_level', $sanitize_data );
} else {
delete_post_meta( $post_id, '_custom_level' );
}
}
add_action('wp_enqueue_scripts', 'my_function', 10);
function my_function() {
wp_enqueue_script('wc-add-to-cart', get_template_directory_uri() .'/тут указать путь куда вы скопировали скрипт add-to-cart.js', WC_VERSION, true);
}
if ( response.error && response.product_url ) {
window.location = response.product_url;
return;
}
$(function() {
let click = 0;
$(document).on('click', 'class/id', function(e) {
e.preventDefault();
click++;
if (click > 1) {
/.../
}
return click;
});
});
<div class="modal-items">
<?php
$cart_items = WC()->cart->get_cart();
foreach( $cart_items as $cart_item_key => $item ) { ?>
<div class="left col-md-3">
<div class="product-image"><!-- Make sure ot check if it's a gallery, if so, get its first image -->
<?php echo $item['data']->get_image(); ?>
</div>
</div>
<div class="right col-md-8">
<h4 class="product-name"><?php echo $item['data']->get_name(); ?></h4>
<div class="product-information">
<span class="product-quantity"><?php echo $item['quantity'] . 'x' ?></span>
<span class="product-price"><?php echo $item['data']->get_price_html(); ?></span>
</div>
<?php
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" aria-label="%s" data-product_id="%s" data-product_sku="%s">X</a>',
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
__( 'Remove this item', 'woocommerce' ),
esc_attr( $item['product_id'] ),
esc_attr( $item['data']->get_sku() )
), $cart_item_key );
?>
</div>
<?php } ?>
</div>
function modal_add_to_cart_fragments( $fragments ) {
ob_start();
?>
<div class="modal-items">
<?php
$cart_items = WC()->cart->get_cart();
foreach( $cart_items as $cart_item_key => $item ) { ?>
<div class="left col-md-3">
<div class="product-image"><!-- Make sure ot check if it's a gallery, if so, get its first image -->
<?php echo $item['data']->get_image(); ?>
</div>
</div>
<div class="right col-md-8">
<h4 class="product-name"><?php echo $item['data']->get_name(); ?></h4>
<div class="product-information">
<span class="product-quantity"><?php echo $item['quantity'] . 'x' ?></span>
<span class="product-price"><?php echo $item['data']->get_price_html(); ?></span>
</div>
<?php
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" aria-label="%s" data-product_id="%s" data-product_sku="%s">X</a>',
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
__( 'Remove this item', 'woocommerce' ),
esc_attr( $item['product_id'] ),
esc_attr( $item['data']->get_sku() )
), $cart_item_key );
?>
</div>
<?php } ?>
</div>
<?php
$fragments['.modal-items'] = ob_get_clean();
return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'modal_add_to_cart_fragments', 10, 1 );