woocommerce
/
src
/
Internal
/
Features
/
ProductBlockEditor
/
ProductTemplates
/
DownloadableProductTrait.php
AbstractProductFormTemplate.php
2 years ago
DownloadableProductTrait.php
2 years ago
Group.php
1 year ago
ProductBlock.php
2 years ago
ProductVariationTemplate.php
1 month ago
Section.php
1 year ago
SimpleProductTemplate.php
1 month ago
Subsection.php
1 year ago
DownloadableProductTrait.php
79 lines
| 1 | <?php |
| 2 | /** |
| 3 | * DownloadableProductTrait |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Features\ProductBlockEditor\ProductTemplates; |
| 7 | |
| 8 | use Automattic\WooCommerce\Admin\Features\Features; |
| 9 | use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\GroupInterface; |
| 10 | |
| 11 | /** |
| 12 | * Downloadable Product Trait. |
| 13 | */ |
| 14 | trait DownloadableProductTrait { |
| 15 | /** |
| 16 | * Adds downloadable blocks to the given parent block. |
| 17 | * |
| 18 | * @param GroupInterface $parent_block The parent block. |
| 19 | */ |
| 20 | private function add_downloadable_product_blocks( $parent_block ) { |
| 21 | // Downloads section. |
| 22 | $product_downloads_section_group = $parent_block->add_section( |
| 23 | array( |
| 24 | 'id' => 'product-downloads-section-group', |
| 25 | 'order' => 50, |
| 26 | 'attributes' => array( |
| 27 | 'blockGap' => 'unit-40', |
| 28 | ), |
| 29 | 'hideConditions' => array( |
| 30 | array( |
| 31 | 'expression' => 'postType === "product" && editedProduct.type !== "simple"', |
| 32 | ), |
| 33 | ), |
| 34 | ) |
| 35 | ); |
| 36 | |
| 37 | $product_downloads_section_group->add_block( |
| 38 | array( |
| 39 | 'id' => 'product-downloadable', |
| 40 | 'blockName' => 'woocommerce/product-toggle-field', |
| 41 | 'order' => 10, |
| 42 | 'attributes' => array( |
| 43 | 'property' => 'downloadable', |
| 44 | 'label' => __( 'Include downloads', 'woocommerce' ), |
| 45 | 'checkedHelp' => __( 'Add any files you\'d like to make available for the customer to download after purchasing, such as instructions or warranty info.', 'woocommerce' ), |
| 46 | 'uncheckedHelp' => __( 'Add any files you\'d like to make available for the customer to download after purchasing, such as instructions or warranty info.', 'woocommerce' ), |
| 47 | ), |
| 48 | ) |
| 49 | ); |
| 50 | |
| 51 | $product_downloads_section_group->add_subsection( |
| 52 | array( |
| 53 | 'id' => 'product-downloads-section', |
| 54 | 'order' => 20, |
| 55 | 'attributes' => array( |
| 56 | 'title' => __( 'Downloads', 'woocommerce' ), |
| 57 | 'description' => sprintf( |
| 58 | /* translators: %1$s: Downloads settings link opening tag. %2$s: Downloads settings link closing tag. */ |
| 59 | __( 'Add any files you\'d like to make available for the customer to download after purchasing, such as instructions or warranty info. Store-wide updates can be managed in your %1$sproduct settings%2$s.', 'woocommerce' ), |
| 60 | '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products§ion=downloadable' ) . '" target="_blank" rel="noreferrer">', |
| 61 | '</a>' |
| 62 | ), |
| 63 | ), |
| 64 | 'hideConditions' => array( |
| 65 | array( |
| 66 | 'expression' => 'editedProduct.downloadable !== true', |
| 67 | ), |
| 68 | ), |
| 69 | ) |
| 70 | )->add_block( |
| 71 | array( |
| 72 | 'id' => 'product-downloads', |
| 73 | 'blockName' => 'woocommerce/product-downloads-field', |
| 74 | 'order' => 10, |
| 75 | ) |
| 76 | ); |
| 77 | } |
| 78 | } |
| 79 |