クラス
ItemPage
ソース ソース
ファイル: src/Pages/ItemPage/ItemPage.php
class ItemPage
{
/**
* Initializes item page
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
public static function init() {
(new ConditionalAssetsLoader())->loadItemPageAssets(function () {
$loadcore = apply_filters('wcexics_filter_load_item_page_default_css', true);
if ($loadcore === true) {
Loader::loadCoreCss();
wp_enqueue_style(
'wcexics-item-page',
WCEXICS_PLUGIN_URL . '/src/Pages/ItemPage/item-page.css',
[],
WCEXICS_VERSION
);
}
wp_enqueue_script(
'wcexics-item-page',
WCEXICS_DIST_JS_URL . '/item-page.js',
[],
WCEXICS_VERSION,
true
);
do_action('wcexics_load_item_page_assets');
});
add_action('usces_theme_item_single_before_options', 'wcexics_combo_set_form');
add_filter('usces_filter_item_sku_button', [get_class(), 'filterAddToCartButton'], 10, 1);
}
/**
* Replaces `Add to Cart` input name with `wcexicsAddToCart` for custom processing
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @global \usc_e_shop $usces
* @global \WP_Post $post
* @param string $html
* @return string
*/
public static function filterAddToCartButton($html) {
global $usces, $post;
$comboset = ComboSet::getComboSetFromSkuCode($post->ID, $usces->itemsku['code']);
if ($comboset instanceof GenericError) {
return $html;
}
if (empty($comboset->getGroups())) {
return $html;
}
$empty = true;
foreach ($comboset->getGroups() as $group) {
if (!empty($group->getItems())) {
$empty = false;
break;
}
}
if ($empty === true) {
return $html;
}
$id = $comboset->getId();
$html = preg_replace('/name="inCart/', 'data-combo-set-id="' . $id . '" name="wcexicsAddToCart', $html);
return $html;
}
}
- filterAddToCartButton — Replaces `Add to Cart` input name with `wcexicsAddToCart` for custom processing
- init — Initializes item page