クラス
ItemPage
ソース ソース
ファイル: src/React/ItemPage/ItemPage.php
class ItemPage extends ItemPageBase
{
const SCRIPT_HANDLE = 'wcexwl-item-react';
/**
* Tracks whether the current SKU hidden input has been created
*
* @var bool
*/
private $skutrackerset = false;
/**
* Loads our React app
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
*/
protected function loadImplementationAssets() {
$assetsmap = include(WCEXWL_PLUGIN_DIR . '/dist/js/React/ItemPage/App.asset.php');
wp_enqueue_script(
self::SCRIPT_HANDLE,
WCEXWL_PLUGIN_URL . '/dist/js/React/ItemPage/App.js',
$assetsmap['dependencies'],
$assetsmap['version'],
true
);
wp_localize_script(
self::SCRIPT_HANDLE,
'wcexwl',
array_merge(
$this->master->getScriptInjectionVariables(),
['postId' => (int)get_the_ID()]
)
);
}
/**
* Updates the value of the currently selected SKU when using `wcex_sku_select`
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param int $post_id
* @return void
*/
public function updateCurrentSku($post_id) {
?>
$('#wcexwl_itempage_current_sku_<?php echo $post_id; ?>').val(data['sku_enc']).trigger('change');
<?php
}
/**
* Adds wishlist button next to "Add to Cart" button on item pages
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param string $html
* @return string
*/
public function addWishlistButton($html) {
global $usces;
$currentsku = urlencode($usces->itemsku['code']);
ob_start();
?>
<div class="wcexwl item-page-buttons flex row-wrap ai-stretch jc-flex-end ml-05rem-children-not-first mt-05rem-children">
<?php echo $html; ?>
<?php if ($this->skutrackerset === false) : ?>
<input
type="hidden"
id="wcexwl_itempage_current_sku_<?php echo esc_attr((int)get_the_ID()); ?>"
value="<?php echo esc_attr($currentsku); ?>"
/>
<?php $this->skutrackerset = true; ?>
<?php endif; ?>
<div
class="wcexwl_react_app wcexwl flex row-wrap ai-stretch"
id="wcexwl_itempage_app_<?php echo esc_attr($currentsku); ?>"
name="<?php echo esc_attr($currentsku); ?>"
></div>
</div>
<?php
$html = (string)ob_get_clean();
return $html;
}
}
- addWishlistButton — Adds wishlist button next to "Add to Cart" button on item pages
- loadImplementationAssets — Loads our React app
- updateCurrentSku — Updates the value of the currently selected SKU when using `wcex_sku_select`